File tree 2 files changed +14
-4
lines changed
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) {
1508
1508
SourceLocation ConstevalLoc;
1509
1509
1510
1510
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
+ }
1515
1518
} else {
1516
1519
if (Tok.is (tok::exclaim)) {
1517
1520
NotLocation = ConsumeToken ();
Original file line number Diff line number Diff line change @@ -357,3 +357,10 @@ void infsNaNs() {
357
357
constexpr double db5 = LD_SNAN ; // expected-error {{constexpr initializer evaluates to nan which is not exactly representable in type 'const double'}}
358
358
constexpr double db6 = INF ;
359
359
}
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