<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Nov 8, 2014 at 7:33 AM, Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: aaronballman<br>
Date: Sat Nov  8 09:33:35 2014<br>
New Revision: 221580<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=221580&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=221580&view=rev</a><br>
Log:<br>
[c++1z] Support for attributes on namespaces and enumerators.<br>
<br>
Added:<br>
    cfe/trunk/test/Parser/cxx1z-attributes.cpp<br>
Modified:<br>
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td<br>
    cfe/trunk/lib/Parse/ParseDecl.cpp<br>
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp<br>
    cfe/trunk/test/Parser/cxx0x-attributes.cpp<br>
    cfe/trunk/www/cxx_status.html<br>
<br>
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=221580&r1=221579&r2=221580&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=221580&r1=221579&r2=221580&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)<br>
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Sat Nov  8 09:33:35 2014<br>
@@ -561,6 +561,9 @@ def warn_cxx98_compat_noexcept_expr : Wa<br>
 def warn_cxx98_compat_nullptr : Warning<<br>
   "'nullptr' is incompatible with C++98">, InGroup<CXX98Compat>, DefaultIgnore;<br>
<br>
+def warn_cxx14_compat_attribute : Warning<<br>
+  "attribute on %0 declarations are incompatible with C++ standards before "<br>
+  "C++1z">, InGroup<CXXPre1zCompat>, DefaultIgnore;<br></blockquote><div><br></div><div>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).</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
 def warn_cxx98_compat_alignas : Warning<"'alignas' is incompatible with C++98">,<br>
   InGroup<CXX98Compat>, DefaultIgnore;<br>
 def warn_cxx98_compat_attribute : Warning<<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=221580&r1=221579&r2=221580&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=221580&r1=221579&r2=221580&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sat Nov  8 09:33:35 2014<br>
@@ -3812,8 +3812,8 @@ void Parser::ParseEnumSpecifier(SourceLo<br>
 ///         enumerator<br>
 ///         enumerator-list ',' enumerator<br>
 ///       enumerator:<br>
-///         enumeration-constant<br>
-///         enumeration-constant '=' constant-expression<br>
+///         enumeration-constant attributes[opt]<br>
+///         enumeration-constant attributes[opt] '=' constant-expression<br>
 ///       enumeration-constant:<br>
 ///         identifier<br>
 ///<br>
@@ -3850,8 +3850,13 @@ void Parser::ParseEnumBody(SourceLocatio<br>
     // If attributes exist after the enumerator, parse them.<br>
     ParsedAttributesWithRange attrs(AttrFactory);<br>
     MaybeParseGNUAttributes(attrs);<br>
-    MaybeParseCXX11Attributes(attrs);<br>
-    ProhibitAttributes(attrs);<br>
+    ProhibitAttributes(attrs); // GNU-style attributes are prohibited.<br>
+    if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {<br>
+      if (!getLangOpts().CPlusPlus1z)<br>
+        Diag(Tok.getLocation(), diag::warn_cxx14_compat_attribute)<br>
+            << "enumerator";<br>
+      ParseCXX11Attributes(attrs);<br>
+    }<br>
<br>
     SourceLocation EqualLoc;<br>
     ExprResult AssignedVal;<br>
<br>
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=221580&r1=221579&r2=221580&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=221580&r1=221579&r2=221580&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Sat Nov  8 09:33:35 2014<br>
@@ -73,7 +73,14 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
   std::vector<IdentifierInfo*> ExtraIdent;<br>
   std::vector<SourceLocation> ExtraNamespaceLoc;<br>
<br>
-  Token attrTok;<br>
+  ParsedAttributesWithRange attrs(AttrFactory);<br>
+  SourceLocation attrLoc;<br>
+  if (getLangOpts().CPlusPlus11 && isCXX11AttributeSpecifier()) {<br>
+    if (!getLangOpts().CPlusPlus1z)<br>
+      Diag(Tok.getLocation(), diag::warn_cxx14_compat_attribute) << "namespace";<br>
+    attrLoc = Tok.getLocation();<br>
+    ParseCXX11Attributes(attrs);<br>
+  }<br>
<br>
   if (Tok.is(tok::identifier)) {<br>
     Ident = Tok.getIdentifierInfo();<br>
@@ -86,9 +93,8 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
   }<br>
<br>
   // Read label attributes, if present.<br>
-  ParsedAttributes attrs(AttrFactory);<br>
   if (Tok.is(tok::kw___attribute)) {<br>
-    attrTok = Tok;<br>
+    attrLoc = Tok.getLocation();<br>
     ParseGNUAttributes(attrs);<br>
   }<br>
<br>
@@ -99,8 +105,8 @@ Decl *Parser::ParseNamespace(unsigned Co<br>
       SkipUntil(tok::semi);<br>
       return nullptr;<br>
     }<br>
-    if (!attrs.empty())<br>
-      Diag(attrTok, diag::err_unexpected_namespace_attributes_alias);<br>
+    if (attrLoc.isValid())<br>
+      Diag(attrLoc, diag::err_unexpected_namespace_attributes_alias);<br>
     if (InlineLoc.isValid())<br>
       Diag(InlineLoc, diag::err_inline_namespace_alias)<br>
           << FixItHint::CreateRemoval(InlineLoc);<br>
<br>
Modified: cfe/trunk/test/Parser/cxx0x-attributes.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-attributes.cpp?rev=221580&r1=221579&r2=221580&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx0x-attributes.cpp?rev=221580&r1=221579&r2=221580&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/Parser/cxx0x-attributes.cpp (original)<br>
+++ cfe/trunk/test/Parser/cxx0x-attributes.cpp Sat Nov  8 09:33:35 2014<br>
@@ -1,4 +1,4 @@<br>
-// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 %s<br>
+// RUN: %clang_cc1 -fcxx-exceptions -fexceptions -fsyntax-only -verify -std=c++11 -Wc++14-compat %s<br>
<br>
 // Need std::initializer_list<br>
 namespace std {<br>
@@ -121,6 +121,7 @@ extern "C++" [[]] { } // expected-error<br>
 [[]] using ns::i; // expected-error {{an attribute list cannot appear here}}<br>
 [[unknown]] using namespace ns; // expected-warning {{unknown attribute 'unknown' ignored}}<br>
 [[noreturn]] using namespace ns; // expected-error {{'noreturn' attribute only applies to functions}}<br>
+namespace [[]] ns2 {} // expected-warning {{attribute on namespace declarations are incompatible with C++ standards before C++1z}}<br>
<br>
 using [[]] alignas(4) [[]] ns::i; // expected-error {{an attribute list cannot appear here}}<br>
 using [[]] alignas(4) [[]] foobar = int; // expected-error {{an attribute list cannot appear here}} expected-error {{'alignas' attribute only applies to}}<br>
@@ -172,7 +173,7 @@ enum [[]] E2; // expected-error {{forbid<br>
 enum [[]] E1;<br>
 enum [[]] E3 : int;<br>
 enum [[]] {<br>
-  k_123 [[]] = 123 // expected-error {{an attribute list cannot appear here}}<br>
+  k_123 [[]] = 123 // expected-warning {{attribute on enumerator declarations are incompatible with C++ standards before C++1z}}<br>
 };<br>
 enum [[]] E1 e; // expected-error {{an attribute list cannot appear here}}<br>
 enum [[]] class E4 { }; // expected-error {{an attribute list cannot appear here}}<br>
<br>
Added: cfe/trunk/test/Parser/cxx1z-attributes.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx1z-attributes.cpp?rev=221580&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/cxx1z-attributes.cpp?rev=221580&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Parser/cxx1z-attributes.cpp (added)<br>
+++ cfe/trunk/test/Parser/cxx1z-attributes.cpp Sat Nov  8 09:33:35 2014<br>
@@ -0,0 +1,12 @@<br>
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++1z %s<br>
+<br>
+namespace [[]] foo {}<br>
+namespace [[]] {}<br>
+namespace [[]] bad = foo; // expected-error {{attributes cannot be specified on namespace alias}}<br>
+<br>
+enum test {<br>
+  bing [[]],<br>
+  bar [[]] = 1,<br>
+  baz [[]][[]],<br>
+  quux [[]][[]] = 4<br>
+};<br>
<br>
Modified: cfe/trunk/www/cxx_status.html<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=221580&r1=221579&r2=221580&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=221580&r1=221579&r2=221580&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/www/cxx_status.html (original)<br>
+++ cfe/trunk/www/cxx_status.html Sat Nov  8 09:33:35 2014<br>
@@ -562,6 +562,11 @@ as the draft C++1z standard evolves.</p><br>
       <td><!--<a href="<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4230.html" target="_blank">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4230.html</a>">-->N4230<!--</a>--></td><br>
       <td class="svn" align="center">SVN</td><br>
     </tr><br>
+    <tr><br>
+      <td>Attributes for namespaces and enumerators</td><br>
+      <td><!--<a href="<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4266.html" target="_blank">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4266.html</a>">-->N4266<!--</a>--></td><br>
+      <td class="svn" align="center">SVN</td><br>
+    </tr><br>
 </table><br>
<br>
 <h2 id="ts">Technical specifications and standing documents</h2><br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>