* g++.dg/cpp1z/decomp14.C: New test.
* g++.dg/cpp1z/decomp15.C: New test.
* g++.dg/cpp1z/decomp16.C: New test.
From-SVN: r242435
2016-11-15 Jakub Jelinek <jakub@redhat.com>
+ * g++.dg/cpp1z/decomp14.C: New test.
+ * g++.dg/cpp1z/decomp15.C: New test.
+ * g++.dg/cpp1z/decomp16.C: New test.
+
* g++.dg/cpp1z/decomp13.C: New test.
* g++.dg/cpp1y/auto-fn33.C (main): Turn // error: ... into dg-bogus.
--- /dev/null
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct A { int f; };
+struct B { int b; };
+struct C : virtual A {};
+struct D : virtual A {};
+struct E { int f; };
+struct F : A { int f; };
+struct G : A, E {};
+struct H : C, D {};
+struct I : A, C {}; // { dg-warning "due to ambiguity" }
+struct J : B {};
+struct K : B, virtual J {}; // { dg-warning "due to ambiguity" }
+struct L : virtual J {};
+struct M : virtual J, L {};
+
+void
+foo (C &c, F &f, G &g, H &h, I &i, K &k, M &m)
+{
+ auto [ ci ] = c; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } }
+ auto [ fi ] = f; // { dg-error "cannot decompose class type 'F': both it and its base class 'A' have non-static data members" }
+ // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .-1 }
+ auto [ gi ] = g; // { dg-error "cannot decompose class type 'G': its base classes 'A' and 'E' have non-static data members" }
+ // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .-1 }
+ auto [ hi ] = h; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } }
+ auto [ ki ] = k; // { dg-error "'B' is an ambiguous base of 'K'" }
+ // { dg-warning "decomposition declaration only available with" "" { target c++14_down } .-1 }
+ auto [ mi ] = m; // { dg-warning "decomposition declaration only available with" "" { target c++14_down } }
+}
--- /dev/null
+// { dg-do compile }
+// { dg-options "-std=c++1z" }
+
+struct A { bool a, b; };
+struct B { int a, b; };
+
+void
+foo ()
+{
+ auto [ a, b ] = A ();
+ for (auto [ a, b ] = A (); a; )
+ ;
+ if (auto [ a, b ] = A (); a)
+ ;
+ switch (auto [ a, b ] = B (); b)
+ {
+ case 2:
+ break;
+ }
+ auto && [ c, d ] = A ();
+ [[maybe_unused]] auto [ e, f ] = A ();
+ alignas (A) auto [ g, h ] = A ();
+ __attribute__((unused)) auto [ i, j ] = A ();
+}
--- /dev/null
+// { dg-do compile }
+// { dg-options "-std=c++1z" }
+
+struct A { bool a, b; };
+struct B { int a, b; };
+
+void
+foo ()
+{
+ auto [ a, b ] = A ();
+ for (; auto [ a, b ] = A (); ) // { dg-error "expected" }
+ ;
+ for (; false; auto [ a, b ] = A ()) // { dg-error "expected" }
+ ;
+ if (auto [ a, b ] = A ()) // { dg-error "expected" }
+ ;
+ if (auto [ a, b ] = A (); auto [ c, d ] = A ()) // { dg-error "expected" }
+ ;
+ if (int d = 5; auto [ a, b ] = A ()) // { dg-error "expected" }
+ ;
+ switch (auto [ a, b ] = B ()) // { dg-error "expected" }
+ {
+ case 2:
+ break;
+ }
+ switch (int d = 5; auto [ a, b ] = B ()) // { dg-error "expected" }
+ {
+ case 2:
+ break;
+ }
+ A e = A ();
+ auto && [ c, d ] = e;
+ auto [ i, j ] = A (), [ k, l ] = A (); // { dg-error "expected" }
+ auto m = A (), [ n, o ] = A (); // { dg-error "expected" }
+}
+
+template <typename T>
+auto [ a, b ] = A (); // { dg-error "expected" }
+
+struct C
+{
+ auto [ e, f ] = A (); // { dg-error "expected" }
+ mutable auto [ g, h ] = A (); // { dg-error "expected" }
+ virtual auto [ i, j ] = A (); // { dg-error "expected" }
+ explicit auto [ k, l ] = A (); // { dg-error "expected" }
+ friend auto [ m, n ] = A (); // { dg-error "expected" }
+};