def warn_cxx14_compat_constexpr_if : Warning<
"constexpr if is incompatible with C++ standards before C++1z">,
DefaultIgnore, InGroup<CXXPre1zCompat>;
+def ext_init_statement : ExtWarn<
+ "'%select{if|switch}0' initialization statements are a C++1z extension">,
+ InGroup<CXX1z>;
+def warn_cxx14_compat_init_statement : Warning<
+ "%select{if|switch}0 initialization statements are incompatible with "
+ "C++ standards before C++1z">, DefaultIgnore, InGroup<CXXPre1zCompat>;
// C++ derived classes
def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;
}
case ConditionOrInitStatement::InitStmtDecl: {
+ Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z
+ ? diag::warn_cxx14_compat_init_statement
+ : diag::ext_init_statement)
+ << (CK == Sema::ConditionKind::Switch);
SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
DeclGroupPtrTy DG = ParseSimpleDeclaration(
Declarator::InitStmtContext, DeclEnd, attrs, /*RequireSemi=*/true);
--- /dev/null
+// RUN: %clang_cc1 -fsyntax-only -std=c++14 -verify %s
+
+void f() {
+ if (bool b = true; b) {} // expected-warning {{'if' initialization statements are a C++1z extension}}
+ switch (int n = 5; n) { // expected-warning {{'switch' initialization statements are a C++1z extension}}
+ case 5: break;
+ }
+}