[cfe-commits] r73626 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDeclCXX.cpp test/Parser/namespace-alias-attr.cpp

Douglas Gregor dgregor at apple.com
Wed Jun 17 12:49:01 PDT 2009


Author: dgregor
Date: Wed Jun 17 14:49:00 2009
New Revision: 73626

URL: http://llvm.org/viewvc/llvm-project?rev=73626&view=rev
Log:
Diagnose the use of attributes on namespace aliases, from Anis Ahmad

Added:
    cfe/trunk/test/Parser/namespace-alias-attr.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
    cfe/trunk/lib/Parse/ParseDeclCXX.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=73626&r1=73625&r2=73626&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Wed Jun 17 14:49:00 2009
@@ -108,6 +108,8 @@
   "expected ';' after method prototype">;
 def err_expected_semi_after_namespace_name : Error<
   "expected ';' after namespace name">;
+def err_unexpected_namespace_attributes_alias : Error<
+  "attributes can not be specified on namespace alias">;
 def err_expected_semi_after_attribute_list : Error<
   "expected ';' after attribute list">;
 def err_expected_semi_after_static_assert : Error<

Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=73626&r1=73625&r2=73626&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Wed Jun 17 14:49:00 2009
@@ -48,6 +48,8 @@
   
   SourceLocation IdentLoc;
   IdentifierInfo *Ident = 0;
+
+  Token attrTok;
   
   if (Tok.is(tok::identifier)) {
     Ident = Tok.getIdentifierInfo();
@@ -56,13 +58,19 @@
   
   // Read label attributes, if present.
   Action::AttrTy *AttrList = 0;
-  if (Tok.is(tok::kw___attribute))
+  if (Tok.is(tok::kw___attribute)) {
+    attrTok = Tok;
+
     // FIXME: save these somewhere.
     AttrList = ParseAttributes();
+  }
   
-  if (Tok.is(tok::equal))
-    // FIXME: Verify no attributes were present.
+  if (Tok.is(tok::equal)) {
+    if (AttrList)
+      Diag(attrTok, diag::err_unexpected_namespace_attributes_alias);
+
     return ParseNamespaceAlias(NamespaceLoc, IdentLoc, Ident, DeclEnd);
+  }
   
   if (Tok.isNot(tok::l_brace)) {
     Diag(Tok, Ident ? diag::err_expected_lbrace : 

Added: cfe/trunk/test/Parser/namespace-alias-attr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/namespace-alias-attr.cpp?rev=73626&view=auto

==============================================================================
--- cfe/trunk/test/Parser/namespace-alias-attr.cpp (added)
+++ cfe/trunk/test/Parser/namespace-alias-attr.cpp Wed Jun 17 14:49:00 2009
@@ -0,0 +1,8 @@
+// RUN: clang-cc -verify %s
+
+namespace A
+{
+}
+
+namespace B __attribute__ (( static )) = A; // expected-error{{attributes can not be specified on namespace alias}}
+





More information about the cfe-commits mailing list