]> granicus.if.org Git - clang/commitdiff
More work on using declarations.
authorAnders Carlsson <andersca@mac.com>
Fri, 28 Aug 2009 03:35:18 +0000 (03:35 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 28 Aug 2009 03:35:18 +0000 (03:35 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80333 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticParseKinds.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Parse/ParseDeclCXX.cpp
lib/Sema/SemaDeclCXX.cpp
test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp [new file with mode: 0644]
test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp [new file with mode: 0644]
test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp

index 01f2a33f07f98294f48d145f46b34ee789e26db0..9a042605bde0b714ff83eec768bbb860304eb67e 100644 (file)
@@ -161,8 +161,8 @@ def err_use_of_tag_name_without_tag : Error<
   "use of tagged type %0 without '%1' tag">;
 def err_expected_ident_in_using : Error<
   "expected an identifier in using directive">;
-def err_unexpected_template_spec_in_using : Error<
-  "use of template specialization in using directive not allowed">;
+def err_using_decl_can_not_refer_to_template_spec : Error<
+  "using declaration can not refer to template specialization">;
 
 
 /// Objective-C parser diagnostics
index 4465c8baa30b9198bcdfe09b025e3bb945c28e39..6876c2c9a872ce5274d586f7b17df10663b2aa76 100644 (file)
@@ -102,9 +102,11 @@ def err_using_dependent_unsupported : Error<
   "dependent using declaration not supported yet">;
 def err_using_decl_nested_name_specifier_is_not_a_base_class : Error<
   "using declaration refers into %0, which is not a base class of %1">;
-def err_using_decl_refers_to_class_member : Error<
-  "using declaration refers to class member">;
-  
+def err_using_decl_can_not_refer_to_class_member : Error<
+  "using declaration can not refer to class member">;
+ def err_using_decl_can_not_refer_to_namespace : Error<
+  "using declaration can not refer to namespace">;
+
 def err_invalid_thread : Error<
   "'__thread' is only allowed on variable declarations">;
 def err_thread_non_global : Error<
index 0a97825fd92b80076f7b4e8f76f6722c208e301b..c002d48d72192e0056ee6c63536cd5faef3c3e43 100644 (file)
@@ -282,7 +282,9 @@ Parser::DeclPtrTy Parser::ParseUsingDeclaration(unsigned Context,
     return DeclPtrTy();
   }
   if (Tok.is(tok::annot_template_id)) {
-    Diag(Tok, diag::err_unexpected_template_spec_in_using);
+    // C++0x N2914 [namespace.udecl]p5:
+    // A using-declaration shall not name a template-id. 
+    Diag(Tok, diag::err_using_decl_can_not_refer_to_template_spec);
     SkipUntil(tok::semi);
     return DeclPtrTy();
   }
index b8384ee780e94ecbcaa4fd86c6bece305502eb95..f10d7315e910e5eed28c6e462d13e3e9a8e38363 100644 (file)
@@ -2151,7 +2151,7 @@ Sema::DeclPtrTy Sema::ActOnUsingDeclaration(Scope *S,
     // C++0x N2914 [namespace.udecl]p8:
     // A using-declaration for a class member shall be a member-declaration.
     if (NNS->getKind() == NestedNameSpecifier::TypeSpec) {
-      Diag(IdentLoc, diag::err_using_decl_refers_to_class_member)
+      Diag(IdentLoc, diag::err_using_decl_can_not_refer_to_class_member)
         << SS.getRange();
       return DeclPtrTy();
     }
@@ -2181,6 +2181,14 @@ Sema::DeclPtrTy Sema::ActOnUsingDeclaration(Scope *S,
     return DeclPtrTy();
   }
 
+  // C++0x N2914 [namespace.udecl]p6:
+  // A using-declaration shall not name a namespace.
+  if (isa<NamespaceDecl>(ND)) {
+    Diag(IdentLoc, diag::err_using_decl_can_not_refer_to_namespace)
+      << SS.getRange();
+    return DeclPtrTy();
+  }
+  
   UsingAlias = 
     UsingDecl::Create(Context, CurContext, IdentLoc, SS.getRange(),
                       ND->getLocation(), UsingLoc, ND, NNS, IsTypeName);
diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp
new file mode 100644 (file)
index 0000000..63e5c3c
--- /dev/null
@@ -0,0 +1,12 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+// C++0x N2914.
+
+struct A {
+  template<class T> void f(T);
+  template<class T> struct X { };
+};
+
+struct B : A {
+  using A::f<double>; // expected-error{{using declaration can not refer to template specialization}}
+  using A::X<int>; // expected-error{{using declaration can not refer to template specialization}}
+};
\ No newline at end of file
diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp
new file mode 100644 (file)
index 0000000..f86f8fb
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: clang-cc -fsyntax-only -verify %s
+// C++0x N2914.
+
+namespace A {
+  namespace B { }
+}
+
+using A::B; // expected-error{{using declaration can not refer to namespace}}
index 07ef7b0b04d296e8b3e3f438782e35ada2589e8b..59137eb8c9d8e22aa3fbf48ad0506d374ea9c0e6 100644 (file)
@@ -6,10 +6,10 @@ struct X {
   static int a;
 };
 
-using X::i; // expected-error{{error: using declaration refers to class member}}
-using X::s; // expected-error{{error: using declaration refers to class member}}
+using X::i; // expected-error{{using declaration can not refer to class member}}
+using X::s; // expected-error{{using declaration can not refer to class member}}
 
 void f() {
-  using X::i; // expected-error{{error: using declaration refers to class member}}
-  using X::s; // expected-error{{error: using declaration refers to class member}}
+  using X::i; // expected-error{{using declaration can not refer to class member}}
+  using X::s; // expected-error{{using declaration can not refer to class member}}
 }