Author: Timm Baeder
Date: 2026-07-10T12:51:39+02:00
New Revision: e4798e75ccbc6f09e5b588713e82edc224f4b22a

URL: 
https://github.com/llvm/llvm-project/commit/e4798e75ccbc6f09e5b588713e82edc224f4b22a
DIFF: 
https://github.com/llvm/llvm-project/commit/e4798e75ccbc6f09e5b588713e82edc224f4b22a.diff

LOG: [clang][bytecode] Don't diagnose definition without body (#208679)

Let the declared_at note point to the declaration in that case.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Interp.cpp
    clang/test/AST/ByteCode/invalid.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index b2af27fc88542..0adcdfe6e78c9 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -1110,8 +1110,10 @@ static bool diagnoseCallableDecl(InterpState &S, CodePtr 
OpPC,
              diag::note_constexpr_invalid_function, 1)
         << DiagDecl->isConstexpr() << (bool)CD << DiagDecl;
 
-    if (DiagDecl->getDefinition())
-      S.Note(DiagDecl->getDefinition()->getLocation(), diag::note_declared_at);
+    const FunctionDecl *Definition;
+    const Stmt *Body = DiagDecl->getBody(Definition);
+    if (Body && Definition)
+      S.Note(Definition->getLocation(), diag::note_declared_at);
     else
       S.Note(DiagDecl->getLocation(), diag::note_declared_at);
   }

diff  --git a/clang/test/AST/ByteCode/invalid.cpp 
b/clang/test/AST/ByteCode/invalid.cpp
index e79b698a32719..930565181b202 100644
--- a/clang/test/AST/ByteCode/invalid.cpp
+++ b/clang/test/AST/ByteCode/invalid.cpp
@@ -218,3 +218,12 @@ namespace InvalidVirtualCast {
   static_assert((X *)(Y *)&z, ""); // both-error {{not an integral constant 
expression}} \
                                    // both-note {{cast that performs the 
conversions of a reinterpret_cast is not allowed in a constant expression}}
 }
+
+namespace DefinitionInBody {
+  int foo(); // both-note {{declared here}}
+  int foo() {
+    static_assert(foo() == 1); // both-error {{not an integral constant 
expression}} \
+                               // both-note {{non-constexpr function 'foo' 
cannot be used in a constant expression}}
+    return 5;
+  }
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to