From 1a26c27eba32f8766c0eeec73fe43634cd814825 Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 2 Sep 2009 01:07:03 +0000 Subject: [PATCH] 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 --- lib/Sema/Sema.h | 7 ++++--- test/CXX/temp/temp.decls/temp.friend/p1.cpp | 4 ++++ 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 friend bool iszero(const A &a) throw(); +}; + int calc1() { Num left = -1; Num right = 1; -- 2.50.1