From: Richard Smith Date: Tue, 18 Oct 2016 20:27:16 +0000 (+0000) Subject: Add missing warning for use of C++1z init-statements in C++14 and before. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89176ac61e151c65c8c083435361f2245d741a96;p=clang Add missing warning for use of C++1z init-statements in C++14 and before. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284530 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index fd9c9626f7..b5b90559b6 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -521,6 +521,12 @@ def ext_constexpr_if : ExtWarn< def warn_cxx14_compat_constexpr_if : Warning< "constexpr if is incompatible with C++ standards before C++1z">, DefaultIgnore, InGroup; +def ext_init_statement : ExtWarn< + "'%select{if|switch}0' initialization statements are a C++1z extension">, + InGroup; +def warn_cxx14_compat_init_statement : Warning< + "%select{if|switch}0 initialization statements are incompatible with " + "C++ standards before C++1z">, DefaultIgnore, InGroup; // C++ derived classes def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">; diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 614ba8fe25..83e6ae4ef5 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -1787,6 +1787,10 @@ Sema::ConditionResult Parser::ParseCXXCondition(StmtResult *InitStmt, } 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); diff --git a/test/SemaCXX/warn-c++1z-extensions.cpp b/test/SemaCXX/warn-c++1z-extensions.cpp new file mode 100644 index 0000000000..9b5e1c205c --- /dev/null +++ b/test/SemaCXX/warn-c++1z-extensions.cpp @@ -0,0 +1,8 @@ +// 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; + } +}