Skip to content

Commit 193aeb4

Browse files
committed
[clang][ExprConst] Avoid initializer diags if there is no init
1 parent 28c819c commit 193aeb4

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

clang/lib/AST/ExprConstant.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3596,6 +3596,7 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
35963596
// expressions here; doing so would regress diagnostics for things like
35973597
// reading from a volatile constexpr variable.
35983598
if ((Info.getLangOpts().CPlusPlus && !VD->hasConstantInitialization() &&
3599+
VD->getAnyInitializer() &&
35993600
VD->mightBeUsableInConstantExpressions(Info.Ctx)) ||
36003601
((Info.getLangOpts().CPlusPlus || Info.getLangOpts().OpenCL) &&
36013602
!Info.getLangOpts().CPlusPlus11 && !VD->hasICEInitializer(Info.Ctx))) {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,10 @@ void splash(Swim& swam) {
4747
}
4848

4949
extern Swim dc;
50-
extern Swim& trident; // expected-note {{declared here}}
50+
extern Swim& trident;
5151

5252
constexpr auto& sandeno = typeid(dc); // ok: can only be typeid(Swim)
5353
constexpr auto& gallagher = typeid(trident); // expected-error {{constexpr variable 'gallagher' must be initialized by a constant expression}}
54-
// expected-note@-1 {{initializer of 'trident' is not a constant expression}}
5554

5655
namespace explicitThis {
5756
struct C {

0 commit comments

Comments
 (0)