From 40e202f7d996f1ee0be33f8ddc20d2d207dfa939 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sat, 14 Oct 2017 00:56:24 +0000 Subject: [PATCH] Fix backwards warning for use of C++17 attributes-on-namespaces-and-enumerators feature. llvm-svn: 315784 --- clang/include/clang/Basic/DiagnosticParseKinds.td | 7 +++++-- clang/lib/Parse/ParseDecl.cpp | 7 ++++--- clang/lib/Parse/ParseDeclCXX.cpp | 7 ++++--- clang/test/Parser/cxx0x-attributes.cpp | 4 ++-- clang/test/SemaCXX/cxx0x-compat.cpp | 7 +++++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index e9b1ecded154..a8d6955da3c0 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -558,10 +558,13 @@ def warn_cxx98_compat_noexcept_expr : Warning< def warn_cxx98_compat_nullptr : Warning< "'nullptr' is incompatible with C++98">, InGroup, DefaultIgnore; -def warn_cxx14_compat_attribute : Warning< +def ext_ns_enum_attribute : Extension< + "attributes on %select{a namespace|an enumerator}0 declaration are " + "a C++17 extension">, InGroup; +def warn_cxx14_compat_ns_enum_attribute : Warning< "attributes on %select{a namespace|an enumerator}0 declaration are " "incompatible with C++ standards before C++17">, - InGroup, DefaultIgnore; + InGroup, DefaultIgnore; def warn_cxx98_compat_alignas : Warning<"'alignas' is incompatible with C++98">, InGroup, DefaultIgnore; def warn_cxx98_compat_attribute : Warning< diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 098bf9b12d7f..21cdc62a1861 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -4413,9 +4413,10 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) { MaybeParseGNUAttributes(attrs); ProhibitAttributes(attrs); // GNU-style attributes are prohibited. if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { - if (!getLangOpts().CPlusPlus1z) - Diag(Tok.getLocation(), diag::warn_cxx14_compat_attribute) - << 1 /*enumerator*/; + Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z + ? diag::warn_cxx14_compat_ns_enum_attribute + : diag::ext_ns_enum_attribute) + << 1 /*enumerator*/; ParseCXX11Attributes(attrs); } diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index b30431660f89..25bb053afc2d 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -77,9 +77,10 @@ Parser::DeclGroupPtrTy Parser::ParseNamespace(unsigned Context, ParsedAttributesWithRange attrs(AttrFactory); SourceLocation attrLoc; if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { - if (!getLangOpts().CPlusPlus1z) - Diag(Tok.getLocation(), diag::warn_cxx14_compat_attribute) - << 0 /*namespace*/; + Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z + ? diag::warn_cxx14_compat_ns_enum_attribute + : diag::ext_ns_enum_attribute) + << 0 /*namespace*/; attrLoc = Tok.getLocation(); ParseCXX11Attributes(attrs); } diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index 5db06bd3f2a3..a803085cd317 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -127,7 +127,7 @@ extern "C++" [[]] { } // expected-error {{an attribute list cannot appear here}} [[]] using ns::i; // expected-error {{an attribute list cannot appear here}} [[unknown]] using namespace ns; // expected-warning {{unknown attribute 'unknown' ignored}} [[noreturn]] using namespace ns; // expected-error {{'noreturn' attribute only applies to functions}} -namespace [[]] ns2 {} // expected-warning {{attributes on a namespace declaration are incompatible with C++ standards before C++17}} +namespace [[]] ns2 {} // expected-warning {{attributes on a namespace declaration are a C++17 extension}} using [[]] alignas(4) [[]] ns::i; // expected-error {{an attribute list cannot appear here}} using [[]] alignas(4) [[]] foobar = int; // expected-error {{an attribute list cannot appear here}} expected-error {{'alignas' attribute only applies to}} @@ -179,7 +179,7 @@ enum [[]] E2; // expected-error {{forbids forward references}} enum [[]] E1; enum [[]] E3 : int; enum [[]] { - k_123 [[]] = 123 // expected-warning {{attributes on an enumerator declaration are incompatible with C++ standards before C++17}} + k_123 [[]] = 123 // expected-warning {{attributes on an enumerator declaration are a C++17 extension}} }; enum [[]] E1 e; // expected-error {{an attribute list cannot appear here}} enum [[]] class E4 { }; // expected-error {{an attribute list cannot appear here}} diff --git a/clang/test/SemaCXX/cxx0x-compat.cpp b/clang/test/SemaCXX/cxx0x-compat.cpp index 8f7aaab6a438..b9ccadd85c2d 100644 --- a/clang/test/SemaCXX/cxx0x-compat.cpp +++ b/clang/test/SemaCXX/cxx0x-compat.cpp @@ -1,5 +1,5 @@ -// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat -verify %s -// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++11-compat -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++98 -Wc++11-compat-pedantic -verify %s +// RUN: %clang_cc1 -fsyntax-only -std=c++17 -Wc++11-compat-pedantic -verify %s #if __cplusplus < 201103L @@ -52,4 +52,7 @@ static_assert(true); // expected-warning {{incompatible with C++ standards befor template int f() { return (N + ...); } // expected-warning {{incompatible with C++ standards before C++17}} +namespace [[]] NS_with_attr {} // expected-warning {{incompatible with C++ standards before C++17}} +enum { e [[]] }; // expected-warning {{incompatible with C++ standards before C++17}} + #endif