]> granicus.if.org Git - clang/commitdiff
Using for attributes voted into C++17.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 24 Jun 2016 12:15:12 +0000 (12:15 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 24 Jun 2016 12:15:12 +0000 (12:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@273666 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDeclCXX.cpp
test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp [new file with mode: 0644]
www/cxx_status.html

index d7ecef77a2fe02e3a49ccc2316a29ea44ffcf523..699e4d6e61553bba130d5c94419e106d3339edee 100644 (file)
@@ -560,6 +560,14 @@ def err_cxx11_attribute_forbids_ellipsis : Error<
   "attribute '%0' cannot be used as an attribute pack">;
 def err_cxx11_attribute_repeated : Error<
   "attribute %0 cannot appear multiple times in an attribute specifier">;
+def warn_cxx14_compat_using_attribute_ns : Warning<
+  "default scope specifier for attributes is incompatible with C++ standards "
+  "before C++1z">, InGroup<CXXPre1zCompat>, DefaultIgnore;
+def ext_using_attribute_ns : ExtWarn<
+  "default scope specifier for attributes is a C++1z extension">,
+  InGroup<CXX1z>;
+def err_using_attribute_ns_conflict : Error<
+  "attribute with scope specifier cannot follow default scope specifier">;
 def err_attributes_not_allowed : Error<"an attribute list cannot appear here">;
 def err_l_square_l_square_not_attribute : Error<
   "C++11 only allows consecutive left square brackets when "
index 5718e1e50e9dd62818a9e4df4bf82c0b87e89d3b..51f1192faebf6aa2da7a9eae2aea551bcb3abeda 100644 (file)
@@ -3771,6 +3771,23 @@ void Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
   ConsumeBracket();
   ConsumeBracket();
 
+  SourceLocation CommonScopeLoc;
+  IdentifierInfo *CommonScopeName = nullptr;
+  if (Tok.is(tok::kw_using)) {
+    Diag(Tok.getLocation(), getLangOpts().CPlusPlus1z
+                                ? diag::warn_cxx14_compat_using_attribute_ns
+                                : diag::ext_using_attribute_ns);
+    ConsumeToken();
+
+    CommonScopeName = TryParseCXX11AttributeIdentifier(CommonScopeLoc);
+    if (!CommonScopeName) {
+      Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
+      SkipUntil(tok::r_square, tok::colon, StopBeforeMatch);
+    }
+    if (!TryConsumeToken(tok::colon) && CommonScopeName)
+      Diag(Tok.getLocation(), diag::err_expected) << tok::colon;
+  }
+
   llvm::SmallDenseMap<IdentifierInfo*, SourceLocation, 4> SeenAttrs;
 
   while (Tok.isNot(tok::r_square)) {
@@ -3799,6 +3816,16 @@ void Parser::ParseCXX11AttributeSpecifier(ParsedAttributes &attrs,
       }
     }
 
+    if (CommonScopeName) {
+      if (ScopeName) {
+        Diag(ScopeLoc, diag::err_using_attribute_ns_conflict)
+            << SourceRange(CommonScopeLoc);
+      } else {
+        ScopeName = CommonScopeName;
+        ScopeLoc = CommonScopeLoc;
+      }
+    }
+
     bool StandardAttr = IsBuiltInOrStandardCXX11Attribute(AttrName, ScopeName);
     bool AttrParsed = false;
 
diff --git a/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp b/test/CXX/dcl.dcl/dcl.attr/dcl.attr.grammar/p2-1z.cpp
new file mode 100644 (file)
index 0000000..192fa12
--- /dev/null
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -std=c++1z -verify %s
+
+[[disable_tail_calls, noduplicate]] void f() {} // expected-warning {{unknown attribute 'disable_tail_calls'}} expected-warning {{unknown attribute 'noduplicate'}}
+
+[[using clang: disable_tail_calls, noduplicate]] void g() {} // ok
+
+[[using]] extern int n; // expected-error {{expected identifier}}
+[[using foo
+] // expected-error {{expected ':'}}
+] extern int n;
+[[using 42:]] extern int n; // expected-error {{expected identifier}}
+[[using clang:]] extern int n; // ok
+[[using blah: clang::optnone]] extern int n; // expected-error {{attribute with scope specifier cannot follow}} expected-warning {{only applies to functions}}
+
+[[using clang: unknown_attr]] extern int n; // expected-warning {{unknown attribute}}
+[[using unknown_ns: something]] extern int n; // expected-warning {{unknown attribute}}
index ef254731b2a95acfa8fece329934f7327b35cbf8..8da905e181ccb778104c99b1f30c888f91880333 100644 (file)
@@ -672,12 +672,12 @@ as the draft C++1z standard evolves.</p>
       <td class="full" align="center">Yes</td>
     </tr>
     <!-- Oulu papers -->
-    <!--
     <tr>
       <td>Using attribute namespaces without repetition</td>
       <td><a href="http://wg21.link/p0028r4">P0028R4</a></td>
       <td class="none" align="center">No</td>
     </tr>
+    <!--
     <tr>
       <td>Dynamic memory allocation for over-aligned data</td>
       <td><a href="http://wg21.link/p0035r4">P0035R4</a></td>