[clang] 4476913 - [clang][Interp] Don't suppress diagnostics for undefined+external funcs

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 15 08:47:01 PDT 2024


Author: Timm Bäder
Date: 2024-03-15T16:43:43+01:00
New Revision: 447691333f0a50a159a9924287d48a8266c8a480

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

LOG: [clang][Interp] Don't suppress diagnostics for undefined+external funcs

Calling them should still generate a diagnostic.

Added: 
    

Modified: 
    clang/lib/AST/Interp/Interp.cpp
    clang/test/AST/Interp/records.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 1b9f3cfd3a1670..0ce64a572c263f 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -485,7 +485,9 @@ bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
         // Don't emit anything if the function isn't defined and we're checking
         // for a constant expression. It might be defined at the point we're
         // actually calling it.
-        if (!DiagDecl->isDefined() && S.checkingPotentialConstantExpression())
+        bool IsExtern = DiagDecl->getStorageClass() == SC_Extern;
+        if (!DiagDecl->isDefined() && !IsExtern &&
+            S.checkingPotentialConstantExpression())
           return false;
 
         // If the declaration is defined _and_ declared 'constexpr', the below

diff  --git a/clang/test/AST/Interp/records.cpp b/clang/test/AST/Interp/records.cpp
index 7ddc56c9b5dfc4..769e48fe478a5f 100644
--- a/clang/test/AST/Interp/records.cpp
+++ b/clang/test/AST/Interp/records.cpp
@@ -1238,3 +1238,9 @@ namespace InvalidCtorInitializer {
   // no crash on evaluating the constexpr ctor.
   constexpr int Z = X().Y; // both-error {{constexpr variable 'Z' must be initialized by a constant expression}}
 }
+
+extern int f(); // both-note {{here}}
+struct HasNonConstExprMemInit {
+  int x = f(); // both-note {{non-constexpr function}}
+  constexpr HasNonConstExprMemInit() {} // both-error {{never produces a constant expression}}
+};


        


More information about the cfe-commits mailing list