Skip to content

Commit 46ad7ff

Browse files
authored
[clang][bytecode] Diagnose non-const initialiers in diagnoseUnknownDecl (#113276)
This is more similar to the diagnostic output of the current interpreter
1 parent 20c5983 commit 46ad7ff

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ static bool diagnoseUnknownDecl(InterpState &S, CodePtr OpPC,
8181
return false;
8282
}
8383

84-
if (!D->getType().isConstQualified())
84+
if (!D->getType().isConstQualified()) {
8585
diagnoseNonConstVariable(S, OpPC, D);
86-
else if (const auto *VD = dyn_cast<VarDecl>(D);
87-
VD && !VD->getAnyInitializer())
88-
diagnoseMissingInitializer(S, OpPC, VD);
86+
} else if (const auto *VD = dyn_cast<VarDecl>(D)) {
87+
if (!VD->getAnyInitializer()) {
88+
diagnoseMissingInitializer(S, OpPC, VD);
89+
} else {
90+
const SourceInfo &Loc = S.Current->getSource(OpPC);
91+
S.FFDiag(Loc, diag::note_constexpr_var_init_non_constant, 1) << VD;
92+
S.Note(VD->getLocation(), diag::note_declared_at);
93+
}
94+
}
8995

9096
return false;
9197
}

clang/test/SemaCXX/c99-variable-length-array.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify -Wvla-extension %s -fexperimental-new-constant-interpreter
23
struct NonPOD {
34
NonPOD();
45
};

0 commit comments

Comments
 (0)