From dcc7140f8667f91d176310a2073faf22d25ec139 Mon Sep 17 00:00:00 2001 From: John McCall Date: Fri, 13 Aug 2010 02:23:42 +0000 Subject: [PATCH] Perform access control when template lookup finds a class template. This is *really* hacky. llvm-svn: 110997 --- clang/include/clang/Sema/Lookup.h | 2 +- clang/lib/Sema/SemaTemplate.cpp | 15 +++++++++++---- clang/test/CXX/class.access/p4.cpp | 9 +++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/clang/include/clang/Sema/Lookup.h b/clang/include/clang/Sema/Lookup.h index 6438dc140565..0ccb7d2d30d3 100644 --- a/clang/include/clang/Sema/Lookup.h +++ b/clang/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/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 5b5fe8ada406..ba697fb39855 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/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/clang/test/CXX/class.access/p4.cpp b/clang/test/CXX/class.access/p4.cpp index 90a1449610f3..b0c33606f1d7 100644 --- a/clang/test/CXX/class.access/p4.cpp +++ b/clang/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'}} +}