tbaeder updated this revision to Diff 326882. tbaeder added a comment. You are right of course. I changed the diff to allow GNU-style attributes and reject everything else.
This is a bit hairy because `[[]]` is an empty attribute list but the `SourceRange` is still valid. We don't know if the source range was for `[[]]` or `__attribute__(())` though. I opted for simply rejecting the empty GNU-style attribute list anyway. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D97362/new/ https://reviews.llvm.org/D97362 Files: clang/include/clang/Parse/Parser.h 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 @@ -179,6 +179,7 @@ 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 __attribute__((pure)) Template<std::size_t>; // We still allow GNU-style attributes here template <> struct [[]] Template<void>; enum [[]] E1 {}; Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ clang/lib/Parse/ParseDeclCXX.cpp @@ -1824,7 +1824,10 @@ } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && TUK == Sema::TUK_Declaration) { // This is an explicit instantiation of a class template. - ProhibitAttributes(attrs); + + // Allow only GNU attributes here. + if (!attrs.hasOnlyGNUAttributes()) + ProhibitAttributes(attrs); TagOrTempResult = Actions.ActOnExplicitInstantiation( getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, Index: clang/include/clang/Parse/Parser.h =================================================================== --- clang/include/clang/Parse/Parser.h +++ clang/include/clang/Parse/Parser.h @@ -1581,6 +1581,19 @@ Range = SourceRange(); } + /// Returns whether all attributes are GNU attributes. + bool hasOnlyGNUAttributes() const { + for (const ParsedAttr &A : *this) { + if (A.getSyntax() != ParsedAttr::Syntax::AS_GNU) + return false; + } + + // If the attr list is empty, but the range is still set, we did parse + // some attributes. Return false in this case, even though we might've + // parsed [[]]. + return Range.isInvalid(); + } + SourceRange Range; }; struct ParsedAttributesViewWithRange : ParsedAttributesView {
Index: clang/test/Parser/cxx0x-attributes.cpp =================================================================== --- clang/test/Parser/cxx0x-attributes.cpp +++ clang/test/Parser/cxx0x-attributes.cpp @@ -179,6 +179,7 @@ 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 __attribute__((pure)) Template<std::size_t>; // We still allow GNU-style attributes here template <> struct [[]] Template<void>; enum [[]] E1 {}; Index: clang/lib/Parse/ParseDeclCXX.cpp =================================================================== --- clang/lib/Parse/ParseDeclCXX.cpp +++ clang/lib/Parse/ParseDeclCXX.cpp @@ -1824,7 +1824,10 @@ } else if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation && TUK == Sema::TUK_Declaration) { // This is an explicit instantiation of a class template. - ProhibitAttributes(attrs); + + // Allow only GNU attributes here. + if (!attrs.hasOnlyGNUAttributes()) + ProhibitAttributes(attrs); TagOrTempResult = Actions.ActOnExplicitInstantiation( getCurScope(), TemplateInfo.ExternLoc, TemplateInfo.TemplateLoc, Index: clang/include/clang/Parse/Parser.h =================================================================== --- clang/include/clang/Parse/Parser.h +++ clang/include/clang/Parse/Parser.h @@ -1581,6 +1581,19 @@ Range = SourceRange(); } + /// Returns whether all attributes are GNU attributes. + bool hasOnlyGNUAttributes() const { + for (const ParsedAttr &A : *this) { + if (A.getSyntax() != ParsedAttr::Syntax::AS_GNU) + return false; + } + + // If the attr list is empty, but the range is still set, we did parse + // some attributes. Return false in this case, even though we might've + // parsed [[]]. + return Range.isInvalid(); + } + SourceRange Range; }; struct ParsedAttributesViewWithRange : ParsedAttributesView {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits