aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Parse/ParseDecl.cpp
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2021-03-03 10:45:07 +0100
committerTimm Bäder <tbaeder@redhat.com>2021-03-31 16:44:19 +0200
commit5018e15fdfda855f130cdb78acb88540046853af (patch)
tree45c71bd304ee3c14e1529bf74b7c00f6172984b6 /clang/lib/Parse/ParseDecl.cpp
parent3bdd674fbf767d719dc67e10bc079cb183dd3a3f (diff)
downloadllvm-5018e15fdfda855f130cdb78acb88540046853af.zip
llvm-5018e15fdfda855f130cdb78acb88540046853af.tar.gz
llvm-5018e15fdfda855f130cdb78acb88540046853af.tar.bz2
[clang][parser] Allow GNU-style attributes in explicit template...
... instantiations They are currently not being diagnosed because ProhibitAttributes() does not handle attribute lists with an invalid source range. But once it does, we need to allow GNU attributes in this place. Additionally, start optionally diagnosing empty attr lists in ProhibitCXX11Attributes(), since ProhibitAttribute() does it. Differential Revision: https://reviews.llvm.org/D97362
Diffstat (limited to 'clang/lib/Parse/ParseDecl.cpp')
-rw-r--r--clang/lib/Parse/ParseDecl.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index a044fbc..104b1b5 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -1607,7 +1607,30 @@ void Parser::DiagnoseProhibitedAttributes(
}
void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
- unsigned DiagID) {
+ unsigned DiagID, bool DiagnoseEmptyAttrs) {
+
+ if (DiagnoseEmptyAttrs && Attrs.empty() && Attrs.Range.isValid()) {
+ // An attribute list has been parsed, but it was empty.
+ // This is the case for [[]].
+ const auto &LangOpts = getLangOpts();
+ auto &SM = PP.getSourceManager();
+ Token FirstLSquare;
+ Lexer::getRawToken(Attrs.Range.getBegin(), FirstLSquare, SM, LangOpts);
+
+ if (FirstLSquare.is(tok::l_square)) {
+ llvm::Optional<Token> SecondLSquare =
+ Lexer::findNextToken(FirstLSquare.getLocation(), SM, LangOpts);
+
+ if (SecondLSquare && SecondLSquare->is(tok::l_square)) {
+ // The attribute range starts with [[, but is empty. So this must
+ // be [[]], which we are supposed to diagnose because
+ // DiagnoseEmptyAttrs is true.
+ Diag(Attrs.Range.getBegin(), DiagID) << Attrs.Range;
+ return;
+ }
+ }
+ }
+
for (const ParsedAttr &AL : Attrs) {
if (!AL.isCXX11Attribute() && !AL.isC2xAttribute())
continue;
@@ -4630,7 +4653,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS,
// or opaque-enum-declaration anywhere.
if (IsElaboratedTypeSpecifier && !getLangOpts().MicrosoftExt &&
!getLangOpts().ObjC) {
- ProhibitAttributes(attrs);
+ ProhibitCXX11Attributes(attrs, diag::err_attributes_not_allowed,
+ /*DiagnoseEmptyAttrs=*/true);
if (BaseType.isUsable())
Diag(BaseRange.getBegin(), diag::ext_enum_base_in_type_specifier)
<< (AllowEnumSpecifier == AllowDefiningTypeSpec::Yes) << BaseRange;