diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-22 02:46:14 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-22 02:46:14 +0000 |
commit | 19e0d959171860e207205d31af223b27c925fbec (patch) | |
tree | 2c857cbec3ba86edd4b4032d33cc1b90ae523bee /lib | |
parent | a734a0eab27678262bea07786b6ff30d5c7a6356 (diff) |
PR14695: Fix assert from bad cast<>. Not every namespace is a NamespaceDecl; it might instead be a TranslationUnitDecl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170976 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 2d82750e1b..e5af2b16d7 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -9541,16 +9541,23 @@ DiagnoseTwoPhaseLookup(Sema &SemaRef, SourceLocation FnLoc, SemaRef.FindAssociatedClassesAndNamespaces(FnLoc, Args, AssociatedNamespaces, AssociatedClasses); - // Never suggest declaring a function within namespace 'std'. Sema::AssociatedNamespaceSet SuggestedNamespaces; DeclContext *Std = SemaRef.getStdNamespace(); for (Sema::AssociatedNamespaceSet::iterator it = AssociatedNamespaces.begin(), end = AssociatedNamespaces.end(); it != end; ++it) { - NamespaceDecl *Assoc = cast<NamespaceDecl>(*it); - if ((!Std || !Std->Encloses(Assoc)) && - Assoc->getQualifiedNameAsString().find("__") == std::string::npos) - SuggestedNamespaces.insert(Assoc); + // Never suggest declaring a function within namespace 'std'. + if (Std && Std->Encloses(*it)) + continue; + + // Never suggest declaring a function within a namespace with a reserved + // name, like __gnu_cxx. + NamespaceDecl *NS = dyn_cast<NamespaceDecl>(*it); + if (NS && + NS->getQualifiedNameAsString().find("__") != std::string::npos) + continue; + + SuggestedNamespaces.insert(*it); } SemaRef.Diag(R.getNameLoc(), diag::err_not_found_by_two_phase_lookup) |