[clang] 6484655 - [clang][Interp] Allow initialization of extern variables via ctors
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 15 04:18:23 PDT 2024
Author: Timm Bäder
Date: 2024-07-15T13:12:52+02:00
New Revision: 6484655f9dd07c6d5669dd540feef3c80af84827
URL: https://github.com/llvm/llvm-project/commit/6484655f9dd07c6d5669dd540feef3c80af84827
DIFF: https://github.com/llvm/llvm-project/commit/6484655f9dd07c6d5669dd540feef3c80af84827.diff
LOG: [clang][Interp] Allow initialization of extern variables via ctors
Added:
Modified:
clang/lib/AST/Interp/Interp.cpp
clang/test/AST/Interp/literals.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index 7b2c0480f80ae..b673cc27aee21 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -248,7 +248,8 @@ bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
if (!Ptr.isExtern())
return true;
- if (Ptr.isInitialized())
+ if (Ptr.isInitialized() ||
+ (Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl))
return true;
if (!S.checkingPotentialConstantExpression() && S.getLangOpts().CPlusPlus) {
diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index 6c214f5a6efa7..9cd65462a0af3 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -1232,6 +1232,13 @@ namespace Extern {
}
static_assert(&ExternNonLiteralVarDecl() == &nl, "");
#endif
+
+ struct A {
+ int b;
+ };
+
+ extern constexpr A a{12};
+ static_assert(a.b == 12, "");
}
#if __cplusplus >= 201402L
More information about the cfe-commits
mailing list