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 @@ -1508,10 +1508,13 @@ StmtResult Parser::ParseIfStatement(SourceLocation *TrailingElseLoc) {
15081508 SourceLocation ConstevalLoc;
15091509
15101510 if (Tok.is (tok::kw_constexpr)) {
1511- Diag (Tok, getLangOpts ().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if
1512- : diag::ext_constexpr_if);
1513- IsConstexpr = true ;
1514- ConsumeToken ();
1511+ // C23 supports constexpr keyword, but only for object definitions.
1512+ if (getLangOpts ().CPlusPlus ) {
1513+ Diag (Tok, getLangOpts ().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if
1514+ : diag::ext_constexpr_if);
1515+ IsConstexpr = true ;
1516+ ConsumeToken ();
1517+ }
15151518 } else {
15161519 if (Tok.is (tok::exclaim)) {
15171520 NotLocation = ConsumeToken ();
Original file line number Diff line number Diff line change @@ -357,3 +357,10 @@ void infsNaNs() {
357357 constexpr double db5 = LD_SNAN ; // expected-error {{constexpr initializer evaluates to nan which is not exactly representable in type 'const double'}}
358358 constexpr double db6 = INF ;
359359}
360+
361+ void constexprif () {
362+ if constexpr (300 ) {} //expected-error {{expected '(' after 'if'}}
363+ }
364+ void constevalif () {
365+ if consteval (300 ) {} //expected-error {{expected '(' after 'if'}}
366+ }
You can’t perform that action at this time.
0 commit comments