SourceLocation ConstevalLoc;
if (Tok.is(tok::kw_constexpr)) {
- Diag(Tok, getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if
- : diag::ext_constexpr_if);
- IsConstexpr = true;
- ConsumeToken();
+ // C23 supports constexpr keyword, but only for object definitions.
+ if (getLangOpts().CPlusPlus) {
+ Diag(Tok, getLangOpts().CPlusPlus17 ? diag::warn_cxx14_compat_constexpr_if
+ : diag::ext_constexpr_if);
+ IsConstexpr = true;
+ ConsumeToken();
+ }
} else {
if (Tok.is(tok::exclaim)) {
NotLocation = ConsumeToken();
constexpr double db5 = LD_SNAN; // expected-error {{constexpr initializer evaluates to nan which is not exactly representable in type 'const double'}}
constexpr double db6 = INF;
}
+
+void constexprif() {
+ if constexpr (300) {} //expected-error {{expected '(' after 'if'}}
+}
+void constevalif() {
+ if consteval (300) {} //expected-error {{expected '(' after 'if'}}
+}