diff options
author | Anders Carlsson <andersca@mac.com> | 2009-08-28 03:35:18 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-08-28 03:35:18 +0000 |
commit | 73b39cf02eaa346c6d7a76c32bf13759de7516db (patch) | |
tree | 8a2a4d0e1d2c0d298636151ab165d6bca963a16c | |
parent | cf9f921268e67703d9cddcf9f2d6ac057c4c3cc8 (diff) |
More work on using declarations.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80333 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Basic/DiagnosticParseKinds.td | 4 | ||||
-rw-r--r-- | include/clang/Basic/DiagnosticSemaKinds.td | 8 | ||||
-rw-r--r-- | lib/Parse/ParseDeclCXX.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 10 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp | 12 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp | 8 | ||||
-rw-r--r-- | test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp | 8 |
7 files changed, 43 insertions, 11 deletions
diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index 01f2a33f07..9a042605bd 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -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 diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 4465c8baa3..6876c2c9a8 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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< diff --git a/lib/Parse/ParseDeclCXX.cpp b/lib/Parse/ParseDeclCXX.cpp index 0a97825fd9..c002d48d72 100644 --- a/lib/Parse/ParseDeclCXX.cpp +++ b/lib/Parse/ParseDeclCXX.cpp @@ -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(); } diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index b8384ee780..f10d7315e9 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -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 index 0000000000..63e5c3cd27 --- /dev/null +++ b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p5-cxx0x.cpp @@ -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 index 0000000000..f86f8fb579 --- /dev/null +++ b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p6-cxx0x.cpp @@ -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}} diff --git a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp index 07ef7b0b04..59137eb8c9 100644 --- a/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp +++ b/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p8-cxx0x.cpp @@ -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}} } |