From: John McCall Date: Wed, 24 Mar 2010 09:04:37 +0000 (+0000) Subject: Walk out of enums when determining effective context. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c1b621daf98d83075a466c6f4ad9904dc845dd09;p=clang Walk out of enums when determining effective context. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99391 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaAccess.cpp b/lib/Sema/SemaAccess.cpp index 5b1a9d880a..7e2520c9ee 100644 --- a/lib/Sema/SemaAccess.cpp +++ b/lib/Sema/SemaAccess.cpp @@ -59,6 +59,9 @@ struct EffectiveContext { : Inner(DC), Dependent(DC->isDependentContext()) { + if (isa(DC)) + DC = cast(DC)->getDeclContext(); + if (isa(DC)) { Function = cast(DC)->getCanonicalDecl(); DC = Function->getDeclContext(); @@ -103,7 +106,14 @@ struct EffectiveContext { } static CXXRecordDecl *FindDeclaringClass(NamedDecl *D) { - CXXRecordDecl *DeclaringClass = cast(D->getDeclContext()); + DeclContext *DC = D->getDeclContext(); + + // This can only happen at top: enum decls only "publish" their + // immediate members. + if (isa(DC)) + DC = cast(DC)->getDeclContext(); + + CXXRecordDecl *DeclaringClass = cast(DC); while (DeclaringClass->isAnonymousStructOrUnion()) DeclaringClass = cast(DeclaringClass->getDeclContext()); return DeclaringClass; diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp index bc69bee657..0c87c07e06 100644 --- a/test/CXX/class.access/p4.cpp +++ b/test/CXX/class.access/p4.cpp @@ -262,3 +262,24 @@ namespace test9 { static int getX() { return x; } // expected-error {{'x' is a private member of 'test9::A'}} }; } + +namespace test10 { + class A { + enum { + value = 10 // expected-note {{declared private here}} + }; + friend class C; + }; + + class B { + enum { + value = A::value // expected-error {{'value' is a private member of 'test10::A'}} + }; + }; + + class C { + enum { + value = A::value + }; + }; +}