Skip to content

Commit

Permalink
[clang][Interp] Allow initialization of extern variables via ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Jul 15, 2024
1 parent 2b5595b commit 6484655
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/AST/Interp/Interp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions clang/test/AST/Interp/literals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6484655

Please sign in to comment.