]> granicus.if.org Git - clang/commitdiff
Perform access control when template lookup finds a class template.
authorJohn McCall <rjmccall@apple.com>
Fri, 13 Aug 2010 02:23:42 +0000 (02:23 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 13 Aug 2010 02:23:42 +0000 (02:23 +0000)
This is *really* hacky.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110997 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/Lookup.h
lib/Sema/SemaTemplate.cpp
test/CXX/class.access/p4.cpp

index 6438dc1405658e1aa8762b280ad27721a3e6e673..0ccb7d2d30d3e65de77cc32698082f535adcbf2c 100644 (file)
@@ -454,7 +454,7 @@ public:
 
   /// Determines whether this lookup is suppressing diagnostics.
   bool isSuppressingDiagnostics() const {
-    return Diagnose;
+    return !Diagnose;
   }
 
   /// Sets a 'context' source range.
index 5b5fe8ada406c9168cbb0639ab71a41cef9fcf90..ba697fb398555239ac46ebc5d4f0af411ebf7e01 100644 (file)
@@ -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<TemplateDecl>((*R.begin())->getUnderlyingDecl());
 
@@ -157,9 +161,12 @@ TemplateNameKind Sema::isTemplateName(Scope *S,
       Template = TemplateName(TD);
     }
 
-    if (isa<FunctionTemplateDecl>(TD))
+    if (isa<FunctionTemplateDecl>(TD)) {
       TemplateKind = TNK_Function_template;
-    else {
+
+      // We'll do this lookup again later.
+      R.suppressDiagnostics();
+    } else {
       assert(isa<ClassTemplateDecl>(TD) || isa<TemplateTemplateParmDecl>(TD));
       TemplateKind = TNK_Type_template;
     }
index 90a1449610f31b5c27a2452f426312f604e23c6a..b0c33606f1d7f8c400dab6cde47bc677e3fb48f6 100644 (file)
@@ -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 <typename T> class Inner { }; // expected-note {{declared private here}}
+  };
+
+  A::Inner<int> s; // expected-error {{'Inner' is a private member of 'test17::A'}}
+}