From: Jakub Jelinek Date: Tue, 15 Nov 2016 17:06:43 +0000 (+0100) Subject: decomp14.C: New test. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5a65a911cccb7d9491ee529b687d9a2fb526ab9d;p=gcc.git decomp14.C: New test. * g++.dg/cpp1z/decomp14.C: New test. * g++.dg/cpp1z/decomp15.C: New test. * g++.dg/cpp1z/decomp16.C: New test. From-SVN: r242435 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a08009b6172..a3e7811f101 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,9 @@ 2016-11-15 Jakub Jelinek + * 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. diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp14.C b/gcc/testsuite/g++.dg/cpp1z/decomp14.C new file mode 100644 index 00000000000..5d6d05fb8a4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp14.C @@ -0,0 +1,30 @@ +// { 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 } } +} diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp15.C b/gcc/testsuite/g++.dg/cpp1z/decomp15.C new file mode 100644 index 00000000000..48d2433a642 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp15.C @@ -0,0 +1,24 @@ +// { 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 (); +} diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp16.C b/gcc/testsuite/g++.dg/cpp1z/decomp16.C new file mode 100644 index 00000000000..d67992bb539 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp16.C @@ -0,0 +1,47 @@ +// { 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 +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" } +};