diff options
author | Anders Carlsson <andersca@mac.com> | 2009-03-28 06:42:02 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2009-03-28 06:42:02 +0000 |
commit | 5721c68299edddd6d6dc32f6ea5441bcfa20dfd8 (patch) | |
tree | a641004c7f2a63cf9cd23ccc58416ee80e31bd27 | |
parent | b0b6f726ab78ca32d60c5970777ae1d383d047df (diff) |
Check that the alias points to a valid namespace.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67925 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDeclCXX.cpp | 15 | ||||
-rw-r--r-- | test/SemaCXX/namespace-alias.cpp | 5 |
2 files changed, 20 insertions, 0 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 4c8437deee..7f8a69e5f3 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -1627,6 +1627,7 @@ Sema::DeclTy *Sema::ActOnUsingDirective(Scope *S, // Lookup namespace name. LookupResult R = LookupParsedName(S, &SS, NamespcName, LookupNamespaceName, false); + // FIXME: Can the result of a namespace lookup ever be ambiguous? if (R.isAmbiguous()) { DiagnoseAmbiguousLookup(R, NamespcName, IdentLoc); return 0; @@ -1693,6 +1694,20 @@ Sema::DeclTy *Sema::ActOnNamespaceAliasDef(Scope *S, return 0; } + // Lookup the namespace name. + LookupResult R = LookupParsedName(S, &SS, NamespaceName, + LookupNamespaceName, false); + // FIXME: Can the result of a namespace lookup ever be ambiguous? + if (R.isAmbiguous()) { + DiagnoseAmbiguousLookup(R, NamespaceName, NamespaceLoc); + return 0; + } + + if (!R) { + Diag(NamespaceLoc, diag::err_expected_namespace_name) << SS.getRange(); + return 0; + } + return 0; } diff --git a/test/SemaCXX/namespace-alias.cpp b/test/SemaCXX/namespace-alias.cpp index 745893082b..7d46d08678 100644 --- a/test/SemaCXX/namespace-alias.cpp +++ b/test/SemaCXX/namespace-alias.cpp @@ -9,3 +9,8 @@ namespace B = N; // expected-error {{redefinition of 'B' as different kind of sy namespace C { } // expected-note {{previous definition is here}} namespace C = N; // expected-error {{redefinition of 'C'}} + +int i; +namespace D = i; // expected-error {{expected namespace name}} + +namespace E = N::Foo; // expected-error {{expected namespace name}} |