Fix a little crasher in friend decls. Thanks again to Eli for finding this.
llvm-svn: 80748
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index 63d2831..e2205d6 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -715,10 +715,11 @@
/// Finds the scope corresponding to the given decl context, if it
/// happens to be an enclosing scope. Otherwise return NULL.
Scope *getScopeForDeclContext(Scope *S, DeclContext *DC) {
- DC = DC->getPrimaryContext();
+ DeclContext *TargetDC = DC->getPrimaryContext();
do {
- if (((DeclContext*) S->getEntity())->getPrimaryContext() == DC)
- return S;
+ if (DeclContext *ScopeDC = (DeclContext*) S->getEntity())
+ if (ScopeDC->getPrimaryContext() == TargetDC)
+ return S;
} while ((S = S->getParent()));
return NULL;
diff --git a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
index 4f0037d..4434d48 100644
--- a/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.friend/p1.cpp
@@ -29,6 +29,10 @@
}
};
+class A {
+ template <typename T> friend bool iszero(const A &a) throw();
+};
+
int calc1() {
Num<int> left = -1;
Num<int> right = 1;