[cfe-commits] r110997 - in /cfe/trunk: include/clang/Sema/Lookup.h lib/Sema/SemaTemplate.cpp test/CXX/class.access/p4.cpp

John McCall rjmccall at apple.com
Thu Aug 12 19:23:42 PDT 2010


Author: rjmccall
Date: Thu Aug 12 21:23:42 2010
New Revision: 110997

URL: http://llvm.org/viewvc/llvm-project?rev=110997&view=rev
Log:
Perform access control when template lookup finds a class template.
This is *really* hacky.


Modified:
    cfe/trunk/include/clang/Sema/Lookup.h
    cfe/trunk/lib/Sema/SemaTemplate.cpp
    cfe/trunk/test/CXX/class.access/p4.cpp

Modified: cfe/trunk/include/clang/Sema/Lookup.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Lookup.h?rev=110997&r1=110996&r2=110997&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Lookup.h (original)
+++ cfe/trunk/include/clang/Sema/Lookup.h Thu Aug 12 21:23:42 2010
@@ -454,7 +454,7 @@
 
   /// Determines whether this lookup is suppressing diagnostics.
   bool isSuppressingDiagnostics() const {
-    return Diagnose;
+    return !Diagnose;
   }
 
   /// Sets a 'context' source range.

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=110997&r1=110996&r2=110997&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Aug 12 21:23:42 2010
@@ -130,11 +130,12 @@
 
   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 @@
     // 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 @@
       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;
     }

Modified: cfe/trunk/test/CXX/class.access/p4.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class.access/p4.cpp?rev=110997&r1=110996&r2=110997&view=diff
==============================================================================
--- cfe/trunk/test/CXX/class.access/p4.cpp (original)
+++ cfe/trunk/test/CXX/class.access/p4.cpp Thu Aug 12 21:23:42 2010
@@ -427,3 +427,12 @@
   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'}}
+}





More information about the cfe-commits mailing list