]> gcc.gnu.org Git - gcc.git/commitdiff
Implement P0969
authorVille Voutilainen <ville.voutilainen@gmail.com>
Thu, 5 Apr 2018 14:43:55 +0000 (17:43 +0300)
committerVille Voutilainen <ville@gcc.gnu.org>
Thu, 5 Apr 2018 14:43:55 +0000 (17:43 +0300)
gcc/cp

Implement P0969
* decl.c (find_decomp_class_base): Check accessibility instead
of declared access, adjust diagnostic.

testsuite/

Implement P0969
* g++.dg/cpp1z/decomp4.C: Adjust.
* g++.dg/cpp1z/decomp38.C: New.

From-SVN: r259129

gcc/cp/ChangeLog
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp1z/decomp38.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/decomp4.C

index 090190612851fbebdb4a10c94d8dbac3fb1e8d74..37d82bd8c4b3f566e1b887a05c7e877e7dcfa0c3 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-05  Ville Voutilainen  <ville.voutilainen@gmail.com>
+
+       Implement P0969
+       * decl.c (find_decomp_class_base): Check accessibility instead
+       of declared access, adjust diagnostic.
+
 2018-04-05  Ville Voutilainen  <ville.voutilainen@gmail.com>
 
        Implement P0961
index 31d9c983e9f380044c62dfcfe9e5f8d1ba22ed24..b2e509e4d05c36da8892dec8b742c5421c2e49d7 100644 (file)
@@ -7322,9 +7322,9 @@ find_decomp_class_base (location_t loc, tree type, tree ret)
        inform (DECL_SOURCE_LOCATION (field), "declared here");
        return error_mark_node;
       }
-    else if (TREE_PRIVATE (field) || TREE_PROTECTED (field))
+    else if (!accessible_p (type, field, true))
       {
-       error_at (loc, "cannot decompose non-public member %qD of %qT",
+       error_at (loc, "cannot decompose inaccessible member %qD of %qT",
                  field, type);
        inform (DECL_SOURCE_LOCATION (field),
                TREE_PRIVATE (field)
diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp38.C b/gcc/testsuite/g++.dg/cpp1z/decomp38.C
new file mode 100644 (file)
index 0000000..fc69c02
--- /dev/null
@@ -0,0 +1,48 @@
+// { dg-additional-options -std=c++17 }
+// { dg-do compile }
+
+class X
+{
+   int a, b;
+   void f()
+   {
+     auto[x,y] = *this;
+   }
+};
+
+class X2
+{
+   int a, b;
+   void f(X2& other)
+   {
+     auto[x,y] = other;
+   }
+};
+
+struct X3
+{
+  friend void foo();
+private:
+  int a;
+};
+
+void foo()
+{
+  X3 x;
+  auto [a] = x;
+}
+
+struct X4
+{
+  int a;
+};
+
+struct X5 : private X4
+{
+  friend void foo2();
+};
+
+void foo2() {
+  X5 x;
+  auto [a] = x;
+}
index e50b882f189f529ecc2aff4a1a180ab75886c082..69b5455df3b94f43ac6eb644630f77c0f661ef83 100644 (file)
@@ -18,10 +18,10 @@ test (A &a, B &b, C &c, D &d, E &e, F &f, G &g, H &h, I &i)
                                        // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 }
   auto [ k ] { b };                    // { dg-error "cannot decompose class type 'B' because it has an anonymous union member" }
                                        // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 }
-  auto [ l, l2 ] = c;                  // { dg-error "cannot decompose non-public member 'C::b' of 'C'" }
+  auto [ l, l2 ] = c;                  // { dg-error "cannot decompose inaccessible member 'C::b' of 'C'" }
                                        // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 }
   auto [ m ] = d;                      // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } }
-  auto [ n ] { e };                    // { dg-error "cannot decompose non-public member 'E::a' of 'E'" }
+  auto [ n ] { e };                    // { dg-error "cannot decompose inaccessible member 'E::a' of 'E'" }
                                        // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } .-1 }
   auto [ o ] { f };                    // { dg-warning "structured bindings only available with -std=c..17 or -std=gnu..17" "" { target c++14_down } }
   auto & [ p ] { g };                  // { dg-error "cannot decompose class type 'G': both it and its base class 'F' have non-static data members" }
This page took 0.09658 seconds and 5 git commands to generate.