r221580 - [c++1z] Support for attributes on namespaces and enumerators.

Aaron Ballman aaron at aaronballman.com
Sat Nov 8 08:46:46 PST 2014


On Sat, Nov 8, 2014 at 11:45 AM, Richard Smith <richard at metafoo.co.uk> wrote:
> On Sat, Nov 8, 2014 at 7:33 AM, Aaron Ballman <aaron at aaronballman.com>
> wrote:
>>
>> Author: aaronballman
>> Date: Sat Nov  8 09:33:35 2014
>> New Revision: 221580
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=221580&view=rev
>> Log:
>> [c++1z] Support for attributes on namespaces and enumerators.
>>
>> Added:
>>     cfe/trunk/test/Parser/cxx1z-attributes.cpp
>> Modified:
>>     cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>>     cfe/trunk/lib/Parse/ParseDecl.cpp
>>     cfe/trunk/lib/Parse/ParseDeclCXX.cpp
>>     cfe/trunk/test/Parser/cxx0x-attributes.cpp
>>     cfe/trunk/www/cxx_status.html
>>
>> Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=221580&r1=221579&r2=221580&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
>> +++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sat Nov  8
>> 09:33:35 2014
>> @@ -561,6 +561,9 @@ def warn_cxx98_compat_noexcept_expr : Wa
>>  def warn_cxx98_compat_nullptr : Warning<
>>    "'nullptr' is incompatible with C++98">, InGroup<CXX98Compat>,
>> DefaultIgnore;
>>
>> +def warn_cxx14_compat_attribute : Warning<
>> +  "attribute on %0 declarations are incompatible with C++ standards
>> before "
>> +  "C++1z">, InGroup<CXXPre1zCompat>, DefaultIgnore;
>
>
> There's a singular/plural mismatch here. Also, I think %select should be
> used here, because while 'namespace' is a source-level construct,
> 'enumerator' is not (and is spelled other ways in other languages, I think).

Good call, I will make that change (and others) momentarily.

Btw, the namespace deprecation, we don't do anything sensible for.
Further work will be forthcoming on that.

Thanks!

~Aaron
>
>>
>>  def warn_cxx98_compat_alignas : Warning<"'alignas' is incompatible with
>> C++98">,
>>    InGroup<CXX98Compat>, DefaultIgnore;
>>  def warn_cxx98_compat_attribute : Warning<
>>
>> Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=221580&r1=221579&r2=221580&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
>> +++ cfe/trunk/lib/Parse/ParseDecl.cpp Sat Nov  8 09:33:35 2014
>> @@ -3812,8 +3812,8 @@ void Parser::ParseEnumSpecifier(SourceLo
>>  ///         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(SourceLocatio
>>      // 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;
>>
>> Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=221580&r1=221579&r2=221580&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
>> +++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Sat Nov  8 09:33:35 2014
>> @@ -73,7 +73,14 @@ Decl *Parser::ParseNamespace(unsigned Co
>>    std::vector<IdentifierInfo*> ExtraIdent;
>>    std::vector<SourceLocation> 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 Co
>>    }
>>
>>    // 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 Co
>>        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);
>>
>> Modified: cfe/trunk/test/Parser/cxx0x-attributes.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-attributes.cpp?rev=221580&r1=221579&r2=221580&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/test/Parser/cxx0x-attributes.cpp (original)
>> +++ cfe/trunk/test/Parser/cxx0x-attributes.cpp Sat Nov  8 09:33:35 2014
>> @@ -1,4 +1,4 @@
>> -// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify
>> -std=c++11 %s
>> +// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify
>> -std=c++11 -Wc++14-compat %s
>>
>>  // Need std::initializer_list
>>  namespace std {
>> @@ -121,6 +121,7 @@ extern "C++" [[]] { } // expected-error
>>  [[]] using ns::i; // expected-error {{an attribute list cannot appear
>> here}}
>>  [[unknown]] using namespace ns; // expected-warning {{unknown attribute
>> 'unknown' ignored}}
>>  [[noreturn]] using namespace ns; // expected-error {{'noreturn' attribute
>> only applies to functions}}
>> +namespace [[]] ns2 {} // expected-warning {{attribute on namespace
>> declarations are incompatible with C++ standards before C++1z}}
>>
>>  using [[]] alignas(4) [[]] ns::i; // expected-error {{an attribute list
>> cannot appear here}}
>>  using [[]] alignas(4) [[]] foobar = int; // expected-error {{an attribute
>> list cannot appear here}} expected-error {{'alignas' attribute only applies
>> to}}
>> @@ -172,7 +173,7 @@ enum [[]] E2; // expected-error {{forbid
>>  enum [[]] E1;
>>  enum [[]] E3 : int;
>>  enum [[]] {
>> -  k_123 [[]] = 123 // expected-error {{an attribute list cannot appear
>> here}}
>> +  k_123 [[]] = 123 // expected-warning {{attribute on enumerator
>> declarations are incompatible with C++ standards before C++1z}}
>>  };
>>  enum [[]] E1 e; // expected-error {{an attribute list cannot appear
>> here}}
>>  enum [[]] class E4 { }; // expected-error {{an attribute list cannot
>> appear here}}
>>
>> Added: cfe/trunk/test/Parser/cxx1z-attributes.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx1z-attributes.cpp?rev=221580&view=auto
>>
>> ==============================================================================
>> --- cfe/trunk/test/Parser/cxx1z-attributes.cpp (added)
>> +++ cfe/trunk/test/Parser/cxx1z-attributes.cpp Sat Nov  8 09:33:35 2014
>> @@ -0,0 +1,12 @@
>> +// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s
>> +
>> +namespace [[]] foo {}
>> +namespace [[]] {}
>> +namespace [[]] bad = foo; // expected-error {{attributes cannot be
>> specified on namespace alias}}
>> +
>> +enum test {
>> +  bing [[]],
>> +  bar [[]] = 1,
>> +  baz [[]][[]],
>> +  quux [[]][[]] = 4
>> +};
>>
>> Modified: cfe/trunk/www/cxx_status.html
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=221580&r1=221579&r2=221580&view=diff
>>
>> ==============================================================================
>> --- cfe/trunk/www/cxx_status.html (original)
>> +++ cfe/trunk/www/cxx_status.html Sat Nov  8 09:33:35 2014
>> @@ -562,6 +562,11 @@ as the draft C++1z standard evolves.</p>
>>        <td><!--<a
>> href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4230.html">-->N4230<!--</a>--></td>
>>        <td class="svn" align="center">SVN</td>
>>      </tr>
>> +    <tr>
>> +      <td>Attributes for namespaces and enumerators</td>
>> +      <td><!--<a
>> href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4266.html">-->N4266<!--</a>--></td>
>> +      <td class="svn" align="center">SVN</td>
>> +    </tr>
>>  </table>
>>
>>  <h2 id="ts">Technical specifications and standing documents</h2>
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
>



More information about the cfe-commits mailing list