diff options
author | John McCall <rjmccall@apple.com> | 2009-09-02 02:15:17 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2009-09-02 02:15:17 +0000 |
commit | 53489322f6574413d906f6a4c66033223e6b1e3f (patch) | |
tree | 9c782539cb1ea8364340349ca5e8b120081eaad7 | |
parent | 1a26c27eba32f8766c0eeec73fe43634cd814825 (diff) |
When adding a friend class declaration to the lookup tables, use the access specifier
of any previous declaration in case we replace it in a class's declaration table.
Fixes bug 4858. This sort of thing makes me reconsider putting friend declarations in
declaration lists.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@80750 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 5 | ||||
-rw-r--r-- | test/CXX/class/class.friend/p1.cpp | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 86222ffe14..113283a644 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -4331,6 +4331,11 @@ CreateNewDecl: if (TUK == TUK_Friend) { // 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/class/class.friend/p1.cpp b/test/CXX/class/class.friend/p1.cpp index 9ba02727a0..3f8778885c 100644 --- a/test/CXX/class/class.friend/p1.cpp +++ b/test/CXX/class/class.friend/p1.cpp @@ -61,6 +61,10 @@ class A { typedef void ftypedef(); friend ftypedef typedeffed_function; // okay (because it's not declared as a member) + + class facet; + friend class facet; // should not assert + class facet {}; }; A::UndeclaredSoFar y; // expected-error {{ unknown type name 'UndeclaredSoFar' }} |