]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/59483 (A nested lambda fails to find a protected name with qualified name)
authorVille Voutilainen <ville.voutilainen@gmail.com>
Mon, 2 Jun 2014 20:47:55 +0000 (23:47 +0300)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 2 Jun 2014 20:47:55 +0000 (16:47 -0400)
PR c++/59483
PR c++/61148
* search.c (accessible_p): Use current_nonlambda_class_type.
* semantics.c (check_accessibility_of_qualified_id): Likewise.

From-SVN: r211147

gcc/cp/ChangeLog
gcc/cp/search.c
gcc/cp/semantics.c
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C [new file with mode: 0644]

index 346782e623b706d11dc266b6f7b38c915dbe629f..9b439a964b5d3038ebaf1850468181af029da9a3 100644 (file)
@@ -1,3 +1,10 @@
+2014-06-02  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       PR c++/59483
+       PR c++/61148
+       * search.c (accessible_p): Use current_nonlambda_class_type.
+       * semantics.c (check_accessibility_of_qualified_id): Likewise.
+
 2014-06-02  Andrew MacLeod  <amacleod@redhat.com>
 
        * decl.c: Include builtins.h.
index c3eed90f6c3632b5a9ade786e0c09e3a2444131d..424b26cd3e1b059b34e5941776411a5d2ab6cea1 100644 (file)
@@ -917,9 +917,11 @@ accessible_p (tree type, tree decl, bool consider_local_p)
       /* Figure out where the reference is occurring.  Check to see if
         DECL is private or protected in this scope, since that will
         determine whether protected access is allowed.  */
-      if (current_class_type)
+      tree ct = current_nonlambda_class_type ();
+      if (ct)
        protected_ok = protected_accessible_p (decl,
-                                              current_class_type, binfo);
+                                              ct,
+                                              binfo);
 
       /* Now, loop through the classes of which we are a friend.  */
       if (!protected_ok)
index 4c13e9dc7398f400ad6ad773f2fcd8a0d4a01a0e..21920b41ca56285e7379daae344af3a0d715c541 100644 (file)
@@ -1836,10 +1836,11 @@ check_accessibility_of_qualified_id (tree decl,
       /* If the reference is to a non-static member of the
         current class, treat it as if it were referenced through
         `this'.  */
+      tree ct;
       if (DECL_NONSTATIC_MEMBER_P (decl)
          && current_class_ptr
-         && DERIVED_FROM_P (scope, current_class_type))
-       qualifying_type = current_class_type;
+         && DERIVED_FROM_P (scope, ct = current_nonlambda_class_type ()))
+       qualifying_type = ct;
       /* Otherwise, use the type indicated by the
         nested-name-specifier.  */
       else
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-59483.C
new file mode 100644 (file)
index 0000000..b5b06d2
--- /dev/null
@@ -0,0 +1,31 @@
+// PR c++/59483
+// { dg-do compile { target c++11 } }
+
+struct X
+{
+protected:
+  int i;
+};
+
+struct Y : X
+{
+  Y()
+  {
+    [&]{ X::i = 3; }();
+  }
+};
+
+template <class T>
+struct Y2 : T
+{
+  Y2()
+  {
+    [&]{ T::i = 3; }();
+  }
+};
+
+int main()
+{
+  Y y;
+  Y2<X> y2;
+}
diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-61148.C
new file mode 100644 (file)
index 0000000..879030c
--- /dev/null
@@ -0,0 +1,33 @@
+// PR c++/61148
+// { dg-do compile { target c++11 } }
+
+class DB
+{
+protected:
+  void foo() {};
+};
+
+class DC : public DB
+{
+public:
+  DC()
+  {
+    [this]() {DB::foo();}();
+  };
+};
+
+template <class T>
+class DC2 : public T
+{
+public:
+  DC2()
+  {
+    [this]() {T::foo();}();
+  };
+};
+
+int main(void)
+{
+  DC x;
+  DC2<DB> x2;
+}