Skip to content

Commit 6484655

Browse files
committed
[clang][Interp] Allow initialization of extern variables via ctors
1 parent 2b5595b commit 6484655

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

clang/lib/AST/Interp/Interp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ bool CheckExtern(InterpState &S, CodePtr OpPC, const Pointer &Ptr) {
248248
if (!Ptr.isExtern())
249249
return true;
250250

251-
if (Ptr.isInitialized())
251+
if (Ptr.isInitialized() ||
252+
(Ptr.getDeclDesc()->asVarDecl() == S.EvaluatingDecl))
252253
return true;
253254

254255
if (!S.checkingPotentialConstantExpression() && S.getLangOpts().CPlusPlus) {

clang/test/AST/Interp/literals.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,13 @@ namespace Extern {
12321232
}
12331233
static_assert(&ExternNonLiteralVarDecl() == &nl, "");
12341234
#endif
1235+
1236+
struct A {
1237+
int b;
1238+
};
1239+
1240+
extern constexpr A a{12};
1241+
static_assert(a.b == 12, "");
12351242
}
12361243

12371244
#if __cplusplus >= 201402L

0 commit comments

Comments
 (0)