Skip to content

Commit 52c8159

Browse files
committed
[Clang][AST] Fix diag regression
1 parent bc24bde commit 52c8159

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

clang/lib/AST/Decl.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -2587,9 +2587,6 @@ APValue *VarDecl::evaluateValueImpl(SmallVectorImpl<PartialDiagnosticAt> &Notes,
25872587
!Notes.empty())
25882588
Result = false;
25892589

2590-
if (Eval->Evaluated.allowConstexprUnknown())
2591-
Result = false;
2592-
25932590
// Ensure the computed APValue is cleaned up later if evaluation succeeded,
25942591
// or that it's empty (so that there's nothing to clean up) if evaluation
25952592
// failed.

clang/lib/AST/ExprConstant.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -16998,6 +16998,18 @@ bool Expr::EvaluateAsInitializer(APValue &Value, const ASTContext &Ctx,
1699816998

1699916999
if (!Info.discardCleanups())
1700017000
llvm_unreachable("Unhandled cleanup; missing full expression marker?");
17001+
17002+
if (Value.allowConstexprUnknown()) {
17003+
assert(Value.isLValue() && "Expected an lvalue");
17004+
auto Base = Value.getLValueBase();
17005+
const auto *NewVD = Base.dyn_cast<const ValueDecl *>();
17006+
if (!NewVD)
17007+
NewVD = VD;
17008+
Info.FFDiag(getExprLoc(), diag::note_constexpr_var_init_non_constant, 1)
17009+
<< NewVD;
17010+
NoteLValueLocation(Info, Base);
17011+
return false;
17012+
}
1700117013
}
1700217014

1700317015
return CheckConstantExpression(Info, DeclLoc, DeclTy, Value,

clang/test/SemaCXX/constant-expression-cxx11.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ namespace CaseStatements {
122122
}
123123

124124
extern int &Recurse1;
125-
int &Recurse2 = Recurse1; // pre-cxx23-note {{declared here}}
125+
int &Recurse2 = Recurse1; // expected-note {{declared here}}
126126
int &Recurse1 = Recurse2;
127-
constexpr int &Recurse3 = Recurse2; // expected-error {{must be initialized by a constant expression}} pre-cxx23-note {{initializer of 'Recurse2' is not a constant expression}}
127+
constexpr int &Recurse3 = Recurse2; // expected-error {{must be initialized by a constant expression}} expected-note {{initializer of 'Recurse2' is not a constant expression}}
128128

129129
extern const int RecurseA;
130130
const int RecurseB = RecurseA; // expected-note {{declared here}}

0 commit comments

Comments
 (0)