diff options
author | Chandler Carruth <chandlerc@gmail.com> | 2011-06-28 21:43:34 +0000 |
---|---|---|
committer | Chandler Carruth <chandlerc@gmail.com> | 2011-06-28 21:43:34 +0000 |
commit | 9af7e8e0cb15b41da930e481bbc3b927ad95f78f (patch) | |
tree | 07896f805f31d4fd960e35381cb8873374f1b861 /lib/Sema/SemaLookup.cpp | |
parent | 99ca47b21f6b32ea8a92b0c8e0bea18170f86b9e (diff) |
Fix an invalid use of ::back() on an newly emptied vector. Also tighten
up several places where we never expect to have NULL pointers to assert
early.
This fixes a valgrind error within CorrectTypo, but not the
non-determinism.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@134032 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaLookup.cpp')
-rw-r--r-- | lib/Sema/SemaLookup.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index a92c9eeb8f..6fa7cd673c 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -3237,6 +3237,7 @@ class NamespaceSpecifierSet { } DeclContextList NamespaceSpecifierSet::BuildContextChain(DeclContext *Start) { + assert(Start && "Bulding a context chain from a null context"); DeclContextList Chain; for (DeclContext *DC = Start->getPrimaryContext(); DC != NULL; DC = DC->getLookupParent()) { @@ -3267,7 +3268,7 @@ void NamespaceSpecifierSet::SortNamespaces() { } void NamespaceSpecifierSet::AddNamespace(NamespaceDecl *ND) { - DeclContext *Ctx = dyn_cast<DeclContext>(ND); + DeclContext *Ctx = cast<DeclContext>(ND); NestedNameSpecifier *NNS = NULL; unsigned NumSpecifiers = 0; DeclContextList NamespaceDeclChain(BuildContextChain(Ctx)); @@ -3275,7 +3276,8 @@ void NamespaceSpecifierSet::AddNamespace(NamespaceDecl *ND) { // Eliminate common elements from the two DeclContext chains for (DeclContextList::reverse_iterator C = CurContextChain.rbegin(), CEnd = CurContextChain.rend(); - C != CEnd && NamespaceDeclChain.back() == *C; ++C) { + C != CEnd && !NamespaceDeclChain.empty() && + NamespaceDeclChain.back() == *C; ++C) { NamespaceDeclChain.pop_back(); } |