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/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/test/Parser/cxx0x-attributes.cpp =================================================================== --- clang/test/Parser/cxx0x-attributes.cpp +++ clang/test/Parser/cxx0x-attributes.cpp @@ -179,6 +179,7 @@ struct [[]] Template t; // expected-error {{an attribute list cannot appear here}} struct [[]] ::template Template u; // expected-error {{an attribute list cannot appear here}} template struct [[]] Template; // expected-error {{an attribute list cannot appear here}} +template struct __attribute__((pure)) Template; // We still allow GNU-style attributes here template <> struct [[]] Template; enum [[]] E1 {};