tbaeder created this revision. tbaeder added a reviewer: aaron.ballman. Herald added a subscriber: jdoerfert. tbaeder requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This call to ProhibitAttributes() is almost always dead code. For GNU attributes, it always is, even though they are being used in explicit template instantiations in, e.g. in `clang/test/CodeGenCXX/visibility.cpp`: #define DEFAULT __attribute__((visibility("default"))) namespace PR11690 { template<class T> struct Class { void size() const { } }; template class DEFAULT Class<char>; } This code is accepted by current `g++` and `clang++`, even though the code claims to reject it because of the attributes. If the attributes are changed to C++ attributes however, `clang++` _does_ reject it: #define DEFAULT [[]] namespace PR11690 { template<class T> struct Class { void size() const { } }; template class DEFAULT Class<char>; } But `g++` still accepts the above code. Simply ignoring the attributes does not work either as it breaks tests (e.g. the visibility test from above). I am not sure why or if GNU-style and C++ attributes should be handled differently here, so I am open for a discussion but this call seems mislead to me. Thanks, Timm Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D97362 Files: clang/lib/Parse/ParseDeclCXX.cpp clang/test/Parser/cxx0x-attributes.cpp Index: clang/test/Parser/cxx0x-attributes.cpp =================================================================== --- clang/test/Parser/cxx0x-attributes.cpp +++ clang/test/Parser/cxx0x-attributes.cpp @@ -178,7 +178,7 @@ struct [[]] N::S s; // expected-error {{an attribute list cannot appear here}} struct [[]] Template<int> t; // expected-error {{an attribute list cannot appear here}} struct [[]] ::template Template<int> u; // expected-error {{an attribute list cannot appear here}} -template struct [[]] Template<char>; // expected-error {{an attribute list cannot appear here}} +template struct [[]] Template<char>; template <> struct [[]] Template<void>; enum [[]] E1 {}; Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ clang/lib/Parse/ParseDeclCXX.cpp @@ -1824,8 +1824,6 @@ } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && TUK == Sema::TUK_Declaration) { // This is an explicit instantiation of a class template. - ProhibitAttributes(attrs); - TagOrTempResult = Actions.ActOnExplicitInstantiation( getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, TagType, StartLoc, SS, TemplateId->Template,
Index: clang/test/Parser/cxx0x-attributes.cpp =================================================================== --- clang/test/Parser/cxx0x-attributes.cpp +++ clang/test/Parser/cxx0x-attributes.cpp @@ -178,7 +178,7 @@ struct [[]] N::S s; // expected-error {{an attribute list cannot appear here}} struct [[]] Template<int> t; // expected-error {{an attribute list cannot appear here}} struct [[]] ::template Template<int> u; // expected-error {{an attribute list cannot appear here}} -template struct [[]] Template<char>; // expected-error {{an attribute list cannot appear here}} +template struct [[]] Template<char>; template <> struct [[]] Template<void>; enum [[]] E1 {}; Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ clang/lib/Parse/ParseDeclCXX.cpp @@ -1824,8 +1824,6 @@ } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && TUK == Sema::TUK_Declaration) { // This is an explicit instantiation of a class template. - ProhibitAttributes(attrs); - TagOrTempResult = Actions.ActOnExplicitInstantiation( getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, TagType, StartLoc, SS, TemplateId->Template,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits