File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -1518,10 +1518,13 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) {
1518
1518
SourceLocation ConstevalLoc;
1519
1519
1520
1520
if (Tok.is (tok::kw_constexpr)) {
1521
- Diag (Tok, getLangOpts ().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if
1522
- : diag::ext_constexpr_if);
1523
- IsConstexpr = true ;
1524
- ConsumeToken ();
1521
+ // C23 supports constexpr keyword, but only for object definitions.
1522
+ if (getLangOpts ().CPlusPlus ) {
1523
+ Diag (Tok, getLangOpts ().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if
1524
+ : diag::ext_constexpr_if);
1525
+ IsConstexpr = true ;
1526
+ ConsumeToken ();
1527
+ }
1525
1528
} else {
1526
1529
if (Tok.is (tok::exclaim)) {
1527
1530
NotLocation = ConsumeToken ();
Original file line number Diff line number Diff line change @@ -367,3 +367,10 @@ struct S10 {
367
367
constexpr struct S10 c = { 255 };
368
368
// FIXME-expected-error@-1 {{constexpr initializer evaluates to 255 which is not exactly representable in 'long long' bit-field with width 8}}
369
369
// See: GH#101299
370
+
371
+ void constexprif () {
372
+ if constexpr (300 ) {} //expected-error {{expected '(' after 'if'}}
373
+ }
374
+ void constevalif () {
375
+ if consteval (300 ) {} //expected-error {{expected '(' after 'if'}}
376
+ }
You can’t perform that action at this time.
0 commit comments