Skip to content

Commit 50b1534

Browse files
committed
[clang][Interp] Don't diagnose non-const reads from the evaluating decl
1 parent 6d61d83 commit 50b1534

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

clang/lib/AST/Interp/EvalEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ EvaluationResult EvalEmitter::interpretExpr(const Expr *E,
5656
EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD,
5757
bool CheckFullyInitialized) {
5858
this->CheckFullyInitialized = CheckFullyInitialized;
59+
S.EvaluatingDecl = VD;
5960

6061
if (const Expr *Init = VD->getAnyInitializer()) {
6162
QualType T = VD->getType();
@@ -69,6 +70,7 @@ EvaluationResult EvalEmitter::interpretDecl(const VarDecl *VD,
6970
if (!this->visitDecl(VD, S.inConstantContext()) && EvalResult.empty())
7071
EvalResult.setInvalid();
7172

73+
S.EvaluatingDecl = nullptr;
7274
return std::move(this->EvalResult);
7375
}
7476

clang/lib/AST/Interp/Interp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ bool CheckConstant(InterpState &S, CodePtr OpPC, const Descriptor *Desc) {
322322
};
323323

324324
if (const auto *D = Desc->asVarDecl();
325-
D && D->hasGlobalStorage() && !IsConstType(D)) {
325+
D && D->hasGlobalStorage() && D != S.EvaluatingDecl && !IsConstType(D)) {
326326
diagnoseNonConstVariable(S, OpPC, D);
327327
return S.inConstantContext();
328328
}

clang/lib/AST/Interp/InterpState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ class InterpState final : public State, public SourceMapper {
121121
InterpFrame *Current = nullptr;
122122
/// Source location of the evaluating expression
123123
SourceLocation EvalLocation;
124+
/// Declaration we're initializing/evaluting, if any.
125+
const VarDecl *EvaluatingDecl = nullptr;
124126
};
125127

126128
} // namespace interp

0 commit comments

Comments
 (0)