kevgs created this revision.
kevgs added reviewers: rsmith, dblaikie.
kevgs added a subscriber: cfe-commits.

Fix for this bug https://llvm.org/bugs/show_bug.cgi?id=27312

http://reviews.llvm.org/D19108

Files:
  lib/Sema/SemaAccess.cpp
  test/SemaTemplate/crash-bug-27258.cpp

Index: test/SemaTemplate/crash-bug-27258.cpp
===================================================================
--- /dev/null
+++ test/SemaTemplate/crash-bug-27258.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+template <class T>
+struct AA {
+  template <T>
+  struct B {};
+};
+
+class C {
+  int i; // expected-note{{implicitly declared private here}}
+  template <class T>
+  template <T>
+  friend struct AA<T>::B;
+};
+
+struct A {
+  template <class T>
+  struct B {
+    void f() {
+      C c;
+      c.i; // expected-error{{'i' is a private member of 'C'}} 
expected-warning{{expression result unused}}
+    }
+  };
+};
Index: lib/Sema/SemaAccess.cpp
===================================================================
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -475,8 +475,8 @@
 
     // If the class's context can't instantiate to the friend's
     // context, it can't be a dependent match.
-    if (!MightInstantiateTo(S, CTD->getDeclContext(),
-                            Friend->getDeclContext()))
+    if (Friend->getDeclContext()->isDependentContext() ||
+        !MightInstantiateTo(S, CTD->getDeclContext(), 
Friend->getDeclContext()))
       continue;
 
     // Otherwise, it's a dependent match.


Index: test/SemaTemplate/crash-bug-27258.cpp
===================================================================
--- /dev/null
+++ test/SemaTemplate/crash-bug-27258.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only %s -verify
+template <class T>
+struct AA {
+  template <T>
+  struct B {};
+};
+
+class C {
+  int i; // expected-note{{implicitly declared private here}}
+  template <class T>
+  template <T>
+  friend struct AA<T>::B;
+};
+
+struct A {
+  template <class T>
+  struct B {
+    void f() {
+      C c;
+      c.i; // expected-error{{'i' is a private member of 'C'}} expected-warning{{expression result unused}}
+    }
+  };
+};
Index: lib/Sema/SemaAccess.cpp
===================================================================
--- lib/Sema/SemaAccess.cpp
+++ lib/Sema/SemaAccess.cpp
@@ -475,8 +475,8 @@
 
     // If the class's context can't instantiate to the friend's
     // context, it can't be a dependent match.
-    if (!MightInstantiateTo(S, CTD->getDeclContext(),
-                            Friend->getDeclContext()))
+    if (Friend->getDeclContext()->isDependentContext() ||
+        !MightInstantiateTo(S, CTD->getDeclContext(), Friend->getDeclContext()))
       continue;
 
     // Otherwise, it's a dependent match.
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to