]> granicus.if.org Git - clang/commitdiff
Diagnose the use of attributes on namespace aliases, from Anis Ahmad
authorDouglas Gregor <dgregor@apple.com>
Wed, 17 Jun 2009 19:49:00 +0000 (19:49 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 17 Jun 2009 19:49:00 +0000 (19:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73626 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
lib/Parse/ParseDeclCXX.cpp
test/Parser/namespace-alias-attr.cpp [new file with mode: 0644]

index e2b9eb7a20b8eec9d1f2a5f2d843f92bd6df9fe7..ccb59eb51c22c040b7336af41c012ce9ea60433d 100644 (file)
@@ -108,6 +108,8 @@ def err_expected_semi_after_method_proto : Error<
   "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<
index 498eaf19cd66c4aceec42f0eb017a1a5e8ff39fa..389ea666f12a333c46a837c06db599118e1ad413 100644 (file)
@@ -48,6 +48,8 @@ Parser::DeclPtrTy Parser::ParseNamespace(unsigned Context,
   
   SourceLocation IdentLoc;
   IdentifierInfo *Ident = 0;
+
+  Token attrTok;
   
   if (Tok.is(tok::identifier)) {
     Ident = Tok.getIdentifierInfo();
@@ -56,13 +58,19 @@ Parser::DeclPtrTy Parser::ParseNamespace(unsigned Context,
   
   // 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 : 
diff --git a/test/Parser/namespace-alias-attr.cpp b/test/Parser/namespace-alias-attr.cpp
new file mode 100644 (file)
index 0000000..9e4072c
--- /dev/null
@@ -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}}
+