]> granicus.if.org Git - clang/commitdiff
Work around a crash when checking access to injected class names
authorJohn McCall <rjmccall@apple.com>
Fri, 13 Aug 2010 07:02:08 +0000 (07:02 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 13 Aug 2010 07:02:08 +0000 (07:02 +0000)
qua templates.  The current fix suppresses the access check entirely
in this case;  to do better, we'd need to be able to say that a
particular lookup result came from a particular injected class name,
which is not easy to do with the current representation of LookupResult.
This is on my known-problems list.

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

lib/Sema/SemaTemplate.cpp
test/CXX/class.access/p4.cpp

index ba697fb398555239ac46ebc5d4f0af411ebf7e01..378c7892734db1d780ae435f0c4d45a81d8faf38 100644 (file)
@@ -88,8 +88,13 @@ static void FilterAcceptableTemplateNames(ASTContext &C, LookupResult &R) {
           filter.erase();
           continue;
         }
-          
-      filter.replace(Repl);
+
+      // FIXME: we promote access to public here as a workaround to
+      // the fact that LookupResult doesn't let us remember that we
+      // found this template through a particular injected class name,
+      // which means we end up doing nasty things to the invariants.
+      // Pretending that access is public is *much* safer.
+      filter.replace(Repl, AS_public);
     }
   }
   filter.done();
index b0c33606f1d7f8c400dab6cde47bc677e3fb48f6..fa6e183890c29b168c693c8cb282d47b52aae300 100644 (file)
@@ -436,3 +436,17 @@ namespace test17 {
 
   A::Inner<int> s; // expected-error {{'Inner' is a private member of 'test17::A'}}
 }
+
+namespace test18 {
+  template <class T> class A {};
+  class B : A<int> {
+    A<int> member;
+  };
+
+  // FIXME: this access to A should be forbidden (because C++ is dumb),
+  // but LookupResult can't express the necessary information to do
+  // the check, so we aggressively suppress access control.
+  class C : B {
+    A<int> member;
+  };
+}