From 730476b50ea63c79e590f91859097e16f88503a1 Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Sat, 8 Nov 2014 15:33:35 +0000 Subject: [c++1z] Support for attributes on namespaces and enumerators. llvm-svn: 221580 --- clang/lib/Parse/ParseDecl.cpp | 13 +++++++++---- clang/lib/Parse/ParseDeclCXX.cpp | 16 +++++++++++----- 2 files changed, 20 insertions(+), 9 deletions(-) (limited to 'clang/lib') diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 69347520489..bc162fc6978 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -3812,8 +3812,8 @@ void Parser::ParseEnumSpecifier(SourceLocation StartLoc, DeclSpec &DS, /// enumerator /// enumerator-list ',' enumerator /// enumerator: -/// enumeration-constant -/// enumeration-constant '=' constant-expression +/// enumeration-constant attributes[opt] +/// enumeration-constant attributes[opt] '=' constant-expression /// enumeration-constant: /// identifier /// @@ -3850,8 +3850,13 @@ void Parser::ParseEnumBody(SourceLocation StartLoc, Decl *EnumDecl) { // If attributes exist after the enumerator, parse them. ParsedAttributesWithRange attrs(AttrFactory); MaybeParseGNUAttributes(attrs); - MaybeParseCXX11Attributes(attrs); - ProhibitAttributes(attrs); + ProhibitAttributes(attrs); // GNU-style attributes are prohibited. + if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { + if (!getLangOpts().CPlusPlus1z) + Diag(Tok.getLocation(), diag::warn_cxx14_compat_attribute) + << "enumerator"; + ParseCXX11Attributes(attrs); + } SourceLocation EqualLoc; ExprResult AssignedVal; diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp index 223046c90d9..1f56c8ba3b5 100644 --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -73,7 +73,14 @@ Decl *Parser::ParseNamespace(unsigned Context, std::vector ExtraIdent; std::vector ExtraNamespaceLoc; - Token attrTok; + ParsedAttributesWithRange attrs(AttrFactory); + SourceLocation attrLoc; + if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) { + if (!getLangOpts().CPlusPlus1z) + Diag(Tok.getLocation(), diag::warn_cxx14_compat_attribute) << "namespace"; + attrLoc = Tok.getLocation(); + ParseCXX11Attributes(attrs); + } if (Tok.is(tok::identifier)) { Ident = Tok.getIdentifierInfo(); @@ -86,9 +93,8 @@ Decl *Parser::ParseNamespace(unsigned Context, } // Read label attributes, if present. - ParsedAttributes attrs(AttrFactory); if (Tok.is(tok::kw___attribute)) { - attrTok = Tok; + attrLoc = Tok.getLocation(); ParseGNUAttributes(attrs); } @@ -99,8 +105,8 @@ Decl *Parser::ParseNamespace(unsigned Context, SkipUntil(tok::semi); return nullptr; } - if (!attrs.empty()) - Diag(attrTok, diag::err_unexpected_namespace_attributes_alias); + if (attrLoc.isValid()) + Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias); if (InlineLoc.isValid()) Diag(InlineLoc, diag::err_inline_namespace_alias) << FixItHint::CreateRemoval(InlineLoc); -- cgit v1.2.3