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) {
15181518 SourceLocation ConstevalLoc;
15191519
15201520 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+ }
15251528 } else {
15261529 if (Tok.is (tok::exclaim)) {
15271530 NotLocation = ConsumeToken ();
Original file line number Diff line number Diff line change @@ -367,3 +367,10 @@ struct S10 {
367367constexpr struct S10 c = { 255 };
368368// FIXME-expected-error@-1 {{constexpr initializer evaluates to 255 which is not exactly representable in 'long long' bit-field with width 8}}
369369// 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