From 82b9fb8e7a05066e690670d2eb386a624b04f684 Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 2 Sep 2009 19:32:14 +0000 Subject: [PATCH] Borrow a friend class's previous declaration's access specifier regardless of whether the current context is dependent. Thanks to Anders for pointing this out. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80828 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 10 +++++----- test/CXX/temp/temp.decls/temp.friend/p1.cpp | 3 +++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 113283a644..e7a327805a 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4329,13 +4329,13 @@ CreateNewDecl: // If this has an identifier, add it to the scope stack. if (TUK == TUK_Friend) { + // We might be replacing an existing declaration in the lookup tables; + // if so, borrow its access specifier. + if (PrevDecl) + New->setAccess(PrevDecl->getAccess()); + // Friend tag decls are visible in fairly strange ways. if (!CurContext->isDependentContext()) { - // We might be replacing an existing declaration in the lookup tables; - // if so, borrow its access specifier. - if (PrevDecl) - New->setAccess(PrevDecl->getAccess()); - DeclContext *DC = New->getDeclContext()->getLookupContext(); DC->makeDeclVisibleInContext(New, /* Recoverable = */ false); if (Scope *EnclosingScope = getScopeForDeclContext(S, DC)) diff --git a/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/test/CXX/temp/temp.decls/temp.friend/p1.cpp index 4434d48389..3777485e1a 100644 --- a/test/CXX/temp/temp.decls/temp.friend/p1.cpp +++ b/test/CXX/temp/temp.decls/temp.friend/p1.cpp @@ -27,6 +27,9 @@ public: value_ += b.value_; return *this; } + + class Representation {}; + friend class Representation; }; class A { -- 2.50.1