Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ Attribute Changes in Clang
- Clang now permits the usage of the placement new operator in ``[[msvc::constexpr]]``
context outside of the std namespace. (#GH74924)

- Clang now disallows the use of attributes after the namespace name. (#GH121407)

Improvements to Clang's diagnostics
-----------------------------------

Expand Down
33 changes: 12 additions & 21 deletions clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,15 @@ Parser::DeclGroupPtrTy Parser::ParseNamespace(DeclaratorContext Context,

ParsedAttributes attrs(AttrFactory);

auto ReadAttributes = [&] {
bool MoreToParse;
do {
MoreToParse = false;
if (Tok.is(tok::kw___attribute)) {
ParseGNUAttributes(attrs);
MoreToParse = true;
}
if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {
Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
? diag::warn_cxx14_compat_ns_enum_attribute
: diag::ext_ns_enum_attribute)
<< 0 /*namespace*/;
ParseCXX11Attributes(attrs);
MoreToParse = true;
}
} while (MoreToParse);
};

ReadAttributes();
MaybeParseGNUAttributes(attrs);
if (isAllowedCXX11AttributeSpecifier()) {
if (getLangOpts().CPlusPlus11)
Diag(Tok.getLocation(), getLangOpts().CPlusPlus17
? diag::warn_cxx14_compat_ns_enum_attribute
: diag::ext_ns_enum_attribute)
<< 0 /*namespace*/;
ParseCXX11Attributes(attrs);
}

if (Tok.is(tok::identifier)) {
Ident = Tok.getIdentifierInfo();
Expand All @@ -126,7 +115,9 @@ Parser::DeclGroupPtrTy Parser::ParseNamespace(DeclaratorContext Context,
}
}

ReadAttributes();
MaybeParseGNUAttributes(attrs);
if (Tok.is(tok::l_square))
CheckProhibitedCXX11Attribute();

SourceLocation attrLoc = attrs.Range.getBegin();

Expand Down
25 changes: 7 additions & 18 deletions clang/test/Parser/namespace-attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,27 @@ namespace __attribute__(()) A
{
}

namespace A __attribute__(())
namespace A __attribute__(()) [[]] // expected-error {{an attribute list cannot appear here}}
{
}

namespace __attribute__(()) [[]] A
{
}

namespace [[]] __attribute__(()) A
{
}

namespace A __attribute__(()) [[]]
{
}

namespace A [[]] __attribute__(())
{
namespace A [[]] __attribute__(()) // expected-error {{an attribute list cannot appear here}} \
// expected-error {{expected '{'}}
{ // expected-error {{expected unqualified-id}}
}

namespace [[]] A __attribute__(())
{
}

namespace __attribute__(()) A [[]]
namespace __attribute__(()) A [[]] // expected-error {{an attribute list cannot appear here}}
{
}

namespace A::B __attribute__(()) // expected-error{{attributes cannot be specified on a nested namespace definition}}
namespace A::B __attribute__(()) // expected-error {{attributes cannot be specified on a nested namespace definition}}
{
}

namespace __attribute__(()) A::B // expected-error{{attributes cannot be specified on a nested namespace definition}}
namespace __attribute__(()) A::B // expected-error {{attributes cannot be specified on a nested namespace definition}}
{
}
Loading