aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2009-09-02 01:07:03 +0000
committerJohn McCall <rjmccall@apple.com>2009-09-02 01:07:03 +0000
commit1a26c27eba32f8766c0eeec73fe43634cd814825 (patch)
treef39b6acf83d50ef8e4933585ecf009e1f026920b
parent9124bccde8e4b3531474b108d74720feac898d75 (diff)
Fix a little crasher in friend decls. Thanks again to Eli for finding this.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80748 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/Sema.h7
-rw-r--r--test/CXX/temp/temp.decls/temp.friend/p1.cpp4
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 63d2831fab..e2205d6df5 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -715,10 +715,11 @@ public:
/// 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/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/test/CXX/temp/temp.decls/temp.friend/p1.cpp
index 4f0037d470..4434d48389 100644
--- a/test/CXX/temp/temp.decls/temp.friend/p1.cpp
+++ b/test/CXX/temp/temp.decls/temp.friend/p1.cpp
@@ -29,6 +29,10 @@ public:
}
};
+class A {
+ template <typename T> friend bool iszero(const A &a) throw();
+};
+
int calc1() {
Num<int> left = -1;
Num<int> right = 1;