From: John McCall Date: Fri, 13 Aug 2010 02:23:42 +0000 (+0000) Subject: Perform access control when template lookup finds a class template. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b8592063413d277f6583715c9a890bd58440c1d1;p=clang Perform access control when template lookup finds a class template. This is *really* hacky. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110997 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/Lookup.h b/include/clang/Sema/Lookup.h index 6438dc1405..0ccb7d2d30 100644 --- a/include/clang/Sema/Lookup.h +++ b/include/clang/Sema/Lookup.h @@ -454,7 +454,7 @@ public: /// Determines whether this lookup is suppressing diagnostics. bool isSuppressingDiagnostics() const { - return Diagnose; + return !Diagnose; } /// Sets a 'context' source range. diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 5b5fe8ada4..ba697fb398 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -130,11 +130,12 @@ TemplateNameKind Sema::isTemplateName(Scope *S, LookupResult R(*this, TName, Name.getSourceRange().getBegin(), LookupOrdinaryName); - R.suppressDiagnostics(); LookupTemplateName(R, S, SS, ObjectType, EnteringContext, MemberOfUnknownSpecialization); - if (R.empty() || R.isAmbiguous()) + if (R.empty() || R.isAmbiguous()) { + R.suppressDiagnostics(); return TNK_Non_template; + } TemplateName Template; TemplateNameKind TemplateKind; @@ -145,6 +146,9 @@ TemplateNameKind Sema::isTemplateName(Scope *S, // template name in other ways. Template = Context.getOverloadedTemplateName(R.begin(), R.end()); TemplateKind = TNK_Function_template; + + // We'll do this lookup again later. + R.suppressDiagnostics(); } else { TemplateDecl *TD = cast((*R.begin())->getUnderlyingDecl()); @@ -157,9 +161,12 @@ TemplateNameKind Sema::isTemplateName(Scope *S, Template = TemplateName(TD); } - if (isa(TD)) + if (isa(TD)) { TemplateKind = TNK_Function_template; - else { + + // We'll do this lookup again later. + R.suppressDiagnostics(); + } else { assert(isa(TD) || isa(TD)); TemplateKind = TNK_Type_template; } diff --git a/test/CXX/class.access/p4.cpp b/test/CXX/class.access/p4.cpp index 90a1449610..b0c33606f1 100644 --- a/test/CXX/class.access/p4.cpp +++ b/test/CXX/class.access/p4.cpp @@ -427,3 +427,12 @@ namespace test16 { void b() { throw A(); } // expected-error{{temporary of type 'test16::A' has private destructor}} \ // expected-error{{exception object of type 'test16::A' has private destructor}} } + +// rdar://problem/8146294 +namespace test17 { + class A { + template class Inner { }; // expected-note {{declared private here}} + }; + + A::Inner s; // expected-error {{'Inner' is a private member of 'test17::A'}} +}