diff options
Diffstat (limited to 'gcc/testsuite')
43 files changed, 2655 insertions, 13 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index df2c843..b3ddaf1 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,185 @@ +2025-08-09 H.J. Lu <hjl.tools@gmail.com> + + PR testsuite/121205 + * gcc.target/i386/asm-hard-reg-2.c (z): Use long long for -m32 + to trigger RA error. + +2025-08-09 Dimitar Dimitrov <dimitar@dinux.eu> + + * g++.dg/modules/class-11_a.H: Skip test for effective + default_packed targets. + * g++.dg/modules/class-11_b.C: Ditto. + +2025-08-09 Paul Thomas <pault@gcc.gnu.org> + + PR fortran/121182 + * gfortran.dg/generic_stmt_1.f90: New test. + * gfortran.dg/generic_stmt_2.f90: New test. + * gfortran.dg/generic_stmt_3.f90: New test. + * gfortran.dg/generic_stmt_4.f90: New test. + +2025-08-09 Dimitar Dimitrov <dimitar@dinux.eu> + + * gcc.dg/torture/hardbool-ai.c: Require target that supports + atomic operations on int types. + +2025-08-08 Andrew Pinski <quic_apinski@quicinc.com> + + PR tree-optimization/120599 + * g++.dg/torture/noncall-eh-1.C: New test. + +2025-08-08 Andrew Pinski <quic_apinski@quicinc.com> + + PR tree-optimization/118946 + PR tree-optimization/121422 + * gcc.dg/pr118946-1.c: New test. + * gcc.dg/torture/pr121422-1.c: New test. + * gcc.dg/torture/pr121422-2.c: New test. + +2025-08-08 David Malcolm <dmalcolm@redhat.com> + + PR diagnostics/116253 + * g++.dg/concepts/nested-diagnostics-1-truncated.C: Update for + renamed keys to -fdiagnostics-set-output=text + * g++.dg/concepts/nested-diagnostics-1.C: Likewise. + * g++.dg/concepts/nested-diagnostics-2.C: Likewise. + * gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c: New + test. + * gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c: New test. + * gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c: + Update for renamed keys to -fdiagnostics-set-output=text. + * gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c: + Likewise. + * gcc.dg/plugin/diagnostic-test-nesting-text-indented.c: Likewise. + * gcc.dg/plugin/plugin.exp: Add the new tests. + +2025-08-08 Christophe Lyon <christophe.lyon@linaro.org> + + PR target/120977 + * gcc.target/arm/cmse/cmse-18.c: Check only the case when FPCXT is + not enabled. + * gcc.target/arm/cmse/cmse-19.c: New test. + +2025-08-08 Pengfei Li <Pengfei.Li2@arm.com> + + PR target/121449 + * g++.target/aarch64/sve/pr121449.C: New test. + +2025-08-08 Alex Coplan <alex.coplan@arm.com> + + PR target/120986 + * gcc.target/aarch64/torture/pr120986-2.c: New test. + +2025-08-08 Alex Coplan <alex.coplan@arm.com> + + PR target/120986 + * gcc.target/aarch64/pr120986-1.c: New test. + +2025-08-08 Jakub Jelinek <jakub@redhat.com> + + PR middle-end/121389 + * c-c++-common/asan/pr121389-1.c: New test. + * c-c++-common/asan/pr121389-2.c: New test. + * c-c++-common/asan/pr121389-3.c: New test. + * c-c++-common/asan/pr121389-4.c: New test. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR c++/117783 + * g++.dg/cpp26/decomp13.C: New test. + * g++.dg/cpp26/decomp14.C: New test. + * g++.dg/cpp26/decomp15.C: New test. + * g++.dg/cpp26/decomp16.C: New test. + * g++.dg/cpp26/decomp17.C: New test. + * g++.dg/cpp26/decomp18.C: New test. + * g++.dg/cpp26/decomp19.C: New test. + * g++.dg/cpp26/decomp20.C: New test. + * g++.dg/cpp26/decomp21.C: New test. + * g++.dg/cpp26/feat-cxx26.C (__cpp_structured_bindings): Expect + 202411 rather than 202403. + +2025-08-07 Richard Sandiford <richard.sandiford@arm.com> + + PR target/121414 + * gcc.target/aarch64/sme/pr121414_1.c: New test. + +2025-08-07 Richard Sandiford <richard.sandiford@arm.com> + + PR rtl-optimization/120718 + * gcc.target/aarch64/sve/acle/general/pr120718.c: New test. + +2025-08-07 Richard Biener <rguenther@suse.de> + + PR tree-optimization/121405 + * gcc.dg/tree-ssa/ssa-fre-107.c: New testcase. + * gcc.target/i386/pr90579.c: Adjust. + +2025-08-07 Pengfei Li <Pengfei.Li2@arm.com> + + * gcc.target/aarch64/sve/peel_ind_11.c: New test. + * gcc.target/aarch64/sve/peel_ind_11_run.c: New test. + * gcc.target/aarch64/sve/peel_ind_12.c: New test. + * gcc.target/aarch64/sve/peel_ind_12_run.c: New test. + * gcc.target/aarch64/sve/peel_ind_13.c: New test. + * gcc.target/aarch64/sve/peel_ind_13_run.c: New test. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * g++.dg/DRs/dr2577-1.C: New test. + * g++.dg/DRs/dr2577-2.C: New test. + * g++.dg/DRs/dr2577-2.h: New file. + * g++.dg/DRs/dr2577-3.C: New test. + * g++.dg/DRs/dr2577-3.h: New file. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * g++.dg/DRs/dr2575.C: New test. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * g++.dg/DRs/dr2576.C: New test. + +2025-08-07 Jakub Jelinek <jakub@redhat.com> + + PR preprocessor/120778 + * gcc.dg/Wkeyword-macro-1.c: New test. + * gcc.dg/Wkeyword-macro-2.c: New test. + * gcc.dg/Wkeyword-macro-3.c: New test. + * gcc.dg/Wkeyword-macro-4.c: New test. + * gcc.dg/Wkeyword-macro-5.c: New test. + * gcc.dg/Wkeyword-macro-6.c: New test. + * gcc.dg/Wkeyword-macro-7.c: New test. + * gcc.dg/Wkeyword-macro-8.c: New test. + * gcc.dg/Wkeyword-macro-9.c: New test. + * g++.dg/warn/Wkeyword-macro-1.C: New test. + * g++.dg/warn/Wkeyword-macro-2.C: New test. + * g++.dg/warn/Wkeyword-macro-3.C: New test. + * g++.dg/warn/Wkeyword-macro-4.C: New test. + * g++.dg/warn/Wkeyword-macro-5.C: New test. + * g++.dg/warn/Wkeyword-macro-6.C: New test. + * g++.dg/warn/Wkeyword-macro-7.C: New test. + * g++.dg/warn/Wkeyword-macro-8.C: New test. + * g++.dg/warn/Wkeyword-macro-9.C: New test. + * g++.dg/warn/Wkeyword-macro-10.C: New test. + * g++.dg/opt/pr82577.C: Don't #define register to nothing for + C++17 and later. Instead define reg macro to nothing for C++17 + and later or to register and use it instead of register. + * g++.dg/modules/atom-preamble-3.C: Add -Wno-keyword-macro to + dg-additional-options. + * g++.dg/template/sfinae17.C (static_assert): Rename macro to ... + (my_static_assert): ... this. + (main): Use my_static_assert instead of static_assert. + +2025-08-07 Stefan Schulze Frielinghaus <stefansf@gcc.gnu.org> + + * gcc.target/s390/bitint-1.c: New test. + * gcc.target/s390/bitint-2.c: New test. + * gcc.target/s390/bitint-3.c: New test. + * gcc.target/s390/bitint-4.c: New test. + 2025-08-06 Sam James <sam@gentoo.org> * g++.dg/cpp26/constexpr-new3.C: Escape '[' and ']'. @@ -2820,7 +3002,7 @@ 2025-07-11 Paul Thomas <pault@gcc.gnu.org> - PR fortran/106135 + PR fortran/106035 * gfortran.dg/import3.f90: Use -std=f2008 and comment on change in error message texts with f2018. * gfortran.dg/import12.f90: New test. diff --git a/gcc/testsuite/c-c++-common/asan/pr121389-1.c b/gcc/testsuite/c-c++-common/asan/pr121389-1.c new file mode 100644 index 0000000..0116d7a --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr121389-1.c @@ -0,0 +1,23 @@ +// PR middle-end/121389 +// { dg-do compile { target musttail } } +// { dg-options "-fsanitize=address" } + +int foo (void); +int bar (void); +int baz (unsigned *); + +int +bar (void) +{ + do + { + unsigned t; + int u = baz (&t); + if (u == 42) + [[gnu::musttail]] return foo (); + if (u == -42) + break; + } + while (1); + return 42; +} diff --git a/gcc/testsuite/c-c++-common/asan/pr121389-2.c b/gcc/testsuite/c-c++-common/asan/pr121389-2.c new file mode 100644 index 0000000..02914f8 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr121389-2.c @@ -0,0 +1,37 @@ +// PR middle-end/121389 +// { dg-do compile { target musttail } } +// { dg-options "-fsanitize=address" } + +int foo (void); +int bar (void); +int baz (unsigned *); + +int +bar (void) +{ + for (int a = 0; a < 420; ++a) + { + for (int b = 0; b < 420; ++b) + { + for (int c = 0; c < 420; ++c) + { + unsigned t; + int u = baz (&t); + if (u == 42) + [[gnu::musttail]] return foo (); + if (u == -42) + break; + if (u == 16) + goto l1; + if (u == 18) + goto l2; + if (u == 20) + goto l3; + } + l3:; + } + l2:; + } + l1:; + return 42; +} diff --git a/gcc/testsuite/c-c++-common/asan/pr121389-3.c b/gcc/testsuite/c-c++-common/asan/pr121389-3.c new file mode 100644 index 0000000..5f71e06 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr121389-3.c @@ -0,0 +1,130 @@ +// PR middle-end/121389 +// { dg-do compile { target musttail } } +// { dg-options "-fsanitize=address" } + +int foo (void); +int bar (void); +int baz (unsigned *); + +int +bar (void) +{ + for (int a = 0; a < 420; ++a) + { + for (int b = 0; b < 420; ++b) + { + for (int c = 0; c < 420; ++c) + { + unsigned t; + int u = baz (&t); + if (u == 42) + [[gnu::musttail]] return foo (); + if (u == -42) + break; + if (u == 16) + goto l1; + if (u == 18) + goto l2; + if (u == 20) + goto l3; + switch (u) + { + case 100: goto l100; + case 101: goto l101; + case 102: goto l102; + case 103: goto l103; + case 104: goto l104; + case 105: goto l105; + case 106: goto l106; + case 107: goto l107; + case 108: goto l108; + case 109: goto l109; + case 110: goto l110; + case 111: goto l111; + case 112: goto l112; + case 113: goto l113; + case 114: goto l114; + case 115: goto l115; + case 116: goto l116; + case 117: goto l117; + case 118: goto l118; + case 119: goto l119; + case 120: goto l120; + case 121: goto l121; + case 122: goto l122; + case 123: goto l123; + case 124: goto l124; + case 125: goto l125; + case 126: goto l126; + case 127: goto l127; + case 128: goto l128; + case 129: goto l129; + } + } + l3:; + foo (); + l100: + foo (); + l101: + foo (); + l102: + foo (); + l103: + foo (); + l104: + foo (); + l105: + foo (); + l106: + foo (); + l107: + foo (); + l108: + foo (); + l109:; + } + l2:; + foo (); + l110: + foo (); + l111: + foo (); + l112: + foo (); + l113: + foo (); + l114: + foo (); + l115: + foo (); + l116: + foo (); + l117: + foo (); + l118: + foo (); + l119:; + } + l1:; + foo (); + l120: + foo (); + l121: + foo (); + l122: + foo (); + l123: + foo (); + l124: + foo (); + l125: + foo (); + l126: + foo (); + l127: + foo (); + l128: + foo (); + l129:; + return 42; +} diff --git a/gcc/testsuite/c-c++-common/asan/pr121389-4.c b/gcc/testsuite/c-c++-common/asan/pr121389-4.c new file mode 100644 index 0000000..2f7b410 --- /dev/null +++ b/gcc/testsuite/c-c++-common/asan/pr121389-4.c @@ -0,0 +1,6 @@ +// PR middle-end/121389 +// { dg-do compile { target musttail } } +// { dg-options "-fsanitize=address -fdisable-tree-switchlower_O0" } +// { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } + +#include "pr121389-3.c" diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C index 0cb1610..5b5e3fe 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1-truncated.C @@ -1,6 +1,6 @@ // { dg-do compile { target c++17 } } // { dg-options "-fconcepts" } -// { dg-additional-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-locations=no" } +// { dg-additional-options "-fdiagnostics-set-output=text:show-nesting=yes,show-nesting-locations=no" } struct dog {}; struct cat {}; diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C index e642676..a071b55 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-1.C @@ -1,6 +1,6 @@ // { dg-do compile { target c++17 } } // { dg-options "-fconcepts" } -// { dg-additional-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-locations=no" } +// { dg-additional-options "-fdiagnostics-set-output=text:show-nesting=yes,show-nesting-locations=no" } // { dg-additional-options "-fconcepts-diagnostics-depth=3" } struct dog {}; diff --git a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C index cc15f11..9530bc1 100644 --- a/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C +++ b/gcc/testsuite/g++.dg/concepts/nested-diagnostics-2.C @@ -1,6 +1,6 @@ // { dg-do compile { target c++17 } } // { dg-options "-fconcepts" } -// { dg-additional-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-locations=no" } +// { dg-additional-options "-fdiagnostics-set-output=text:show-nesting=yes,show-nesting-locations=no" } struct dog{}; struct cat{}; diff --git a/gcc/testsuite/g++.dg/cpp26/decomp13.C b/gcc/testsuite/g++.dg/cpp26/decomp13.C new file mode 100644 index 0000000..d01590f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp13.C @@ -0,0 +1,52 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do compile { target c++11 } } +// { dg-options "" } + +namespace std { + template<typename T> struct tuple_size; + template<int, typename> struct tuple_element; +} + +struct S { int a, b, c, d; }; +struct T { + int a[5]; + template <int I> int &get () { return a[I]; } +}; + +template<> struct std::tuple_size<T> { static const int value = 5; }; +template<int I> struct std::tuple_element<I,T> { using type = int; }; + +template <int N> +void +foo () +{ + auto [a, ...b, c] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + auto [...d] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + auto [...e, f, ...g, h] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "multiple packs in structured binding declaration" "" { target *-*-* } .-2 } + auto [i, j, k, l, ...m, n] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "6 names provided for structured binding" "" { target *-*-* } .-2 } + // { dg-message "while 'S' decomposes into 4 elements" "" { target *-*-* } .-3 } + auto [o, ...p, q, r, s] = S (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + auto [t, u, v, w, x, ...y, z] = T (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "7 names provided for structured binding" "" { target *-*-* } .-2 } + // { dg-message "while 'T' decomposes into 5 elements" "" { target *-*-* } .-3 } + int aa[] = { 1, 2, 3 }; + const auto & [ab, ...ac, ad, ae, af] = aa; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "5 names provided for structured binding" "" { target *-*-* } .-2 } + // { dg-message "while 'const int \\\[3\\\]' decomposes into 3 elements" "" { target *-*-* } .-3 } +} + +void +bar () +{ + auto [a, ...b, c, d] = S (); // { dg-error "structured binding pack outside of template" } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp14.C b/gcc/testsuite/g++.dg/cpp26/decomp14.C new file mode 100644 index 0000000..f626ec9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp14.C @@ -0,0 +1,474 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +struct S { + int a; long long b; short c; + explicit operator bool () const noexcept { return true; } +}; +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +struct T { + short c; int a; long long b; + template <int I> + typename std::tuple_element<I, T>::type &get (); + template <int I> + typename std::tuple_element<I, const T>::type &get () const; + explicit operator bool () const noexcept { return false; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 3; }; +template <> +struct std::tuple_element<0, T> { typedef int type; }; +template <> +struct std::tuple_element<1, T> { typedef long long type; }; +template <> +struct std::tuple_element<2, T> { typedef short type; }; +template <> +std::tuple_element<0, T>::type &T::get <0> () { return a; } +template <> +std::tuple_element<1, T>::type &T::get <1> () { return b; } +template <> +std::tuple_element<2, T>::type &T::get <2> () { return c; } +template <> +struct std::tuple_size<const T> { static constexpr int value = 3; }; +template <> +struct std::tuple_element<0, const T> { typedef const int type; }; +template <> +struct std::tuple_element<1, const T> { typedef const long long type; }; +template <> +struct std::tuple_element<2, const T> { typedef const short type; }; +template <> +std::tuple_element<0, const T>::type &T::get <0> () const { return a; } +template <> +std::tuple_element<1, const T>::type &T::get <1> () const { return b; } +template <> +std::tuple_element<2, const T>::type &T::get <2> () const { return c; } +template <typename T, typename U> +struct same_type { static const bool value = false; }; +template <typename T> +struct same_type<T, T> { static const bool value = true; }; + +int +sum () +{ + return 0; +} + +template <typename T, typename ...A> +T +sum (T x, A... y) +{ + return x + sum (y...); +} + +template <typename T> +T +square (T x) +{ + return x * x; +} + +template <typename T> +T & +ref (T &x) +{ + return x; +} + +using size_t = decltype (sizeof 0); + +template <int N> +size_t +foo () +{ + S s = S { 1, 2, 3 }; + auto [sa, sb, sc] = S { 1, 2, 3 }; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (sa), int>::value, ""); + static_assert (same_type <decltype (sb), long long>::value, ""); + static_assert (same_type <decltype (sc), short>::value, ""); + auto [sd, ...se] = S { 1, 2, 3 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + constexpr size_t ses = sizeof... (se); + static_assert (sizeof... (se) == 2, ""); + static_assert (same_type <decltype (sd), int>::value, ""); + static_assert (same_type <decltype (se...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (se...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + const auto & [...sf [[]], sg] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sf) == 2, ""); + static_assert (same_type <decltype (sf...[0]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sf...[1]), const long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sg), const short>::value, ""); + auto [sh, si, sj [[]], ...sk] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sk) == 0, ""); + static_assert (same_type <decltype (sh), int>::value, ""); + static_assert (same_type <decltype (si), long long>::value, ""); + static_assert (same_type <decltype (sj), short>::value, ""); + auto && [sl, ...sm [[maybe_unused]], sn] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sm) == 1, ""); + static_assert (same_type <decltype (sl), int>::value, ""); + static_assert (same_type <decltype (sm...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sn), short>::value, ""); + auto [...so] = S { 1, 2, 3 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (so) == 3, ""); + static_assert (same_type <decltype (so...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (so...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (so...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...sp, sq, sr, ss [[maybe_unused]]] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sp) == 0, ""); + static_assert (same_type <decltype (sq), int>::value, ""); + static_assert (same_type <decltype (sr), long long>::value, ""); + static_assert (same_type <decltype (ss), short>::value, ""); + auto [st, ...su, sv, sw] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (su) == 0, ""); + static_assert (same_type <decltype (st), int>::value, ""); + static_assert (same_type <decltype (sv), long long>::value, ""); + static_assert (same_type <decltype (sw), short>::value, ""); + if (sa != 1 || sb != 2 || sc != 3 + || sd != 1 || se...[0] != 2 || se...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sf...[0] != 1 || sf...[1] != 2 || sg != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sh != 1 || si != 2 || sj != 3 + || sl != 1 || sm...[0] != 2 || sn != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || so...[0] != 1 || so...[1] != 2 || so...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sq != 1 || sr != 2 || ss != 3 + || st != 1 || sv != 2 || sw != 3 + || sum (se...) != 5 + || sum <decltype (se)...> (se...) != 5 + || sum (square (square (se))...) != 97 + || sum (sf...) != 3 + || sum (sk...) != 0 + || sum (sm...) != 2 + || sum (so...) != 6 + || sum <decltype (so)...> (so...) != 6 + || sum (square (so)...) != 14 + || sum (sp...) != 0 + || sum (su...) != 0 + || (se + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + sf) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + sk) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (sm + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (so + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (sp + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + su) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + S s2[] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; + int i = 0; + for (auto [sx, ...sy [[]]] : s2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sy) == 2, ""); + static_assert (same_type <decltype (sx), int>::value, ""); + static_assert (same_type <decltype (sy...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sy...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sx != i * 3 + 1 || sum (sy...) != i * 6 + 5) + __builtin_abort (); + auto fn1 = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn1 (); + auto fn2 = [&sy..., &i] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn2 (); + auto fn3 = [&...sy2 = sy, &i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn3 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn4 = [&...sy3 = ref (sy), &i] () { if (sum (sy3...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn4 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn5 = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn5 (); + auto fn6 = [sy..., i] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn6 (); + auto fn7 = [...sy2 = sy, i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn7 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn8 = [...sy3 = square (sy), i] () { if (sum (sy3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn8 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn9 = [&] () { auto fn = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn9 (); + auto fn10 = [&sy..., &i] () { auto fn = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn10 (); + auto fn11 = [&] () { auto fn = [&...sy2 = sy, &i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn11 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn12 = [&sy..., &i] () { auto fn = [&...sy3 = ref (sy), &i] () { if (sum (sy3...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn12 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn13 = [=] () { auto fn = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn13 (); + auto fn14 = [sy..., i] () { auto fn = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn14 (); + auto fn15 = [=] () { auto fn = [...sy2 = sy, i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn15 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn16 = [&sy..., &i] () { auto fn = [...sy3 = square (sy), i] () { if (sum (sy3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn16 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + ++i; + } + i = 0; + for (auto [...sz] : s2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (sz) == 3, ""); + static_assert (same_type <decltype (sz...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sz...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sz...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (sz...) != i * 9 + 6) + __builtin_abort (); + auto fn = [=] () { if (sum (sz...) != i * 9 + 6) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn (); + ++i; + } + if (auto [...sx, sy] = s) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + { + static_assert (sizeof... (sx) == 2, ""); + static_assert (same_type <decltype (sx...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sx...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sy), short>::value, ""); + if (sum (sx...) != 3 || sy != 3) + __builtin_abort (); + } + else + __builtin_abort (); + T t = T { 3, 1, 2 }; + auto [ta, tb, tc] = T { 3, 1, 2 }; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (ta), int>::value, ""); + static_assert (same_type <decltype (tb), long long>::value, ""); + static_assert (same_type <decltype (tc), short>::value, ""); + auto [td [[maybe_unused]], ...te] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (te) == 2, ""); + static_assert (same_type <decltype (td), int>::value, ""); + static_assert (same_type <decltype (te...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (te...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...tf [[maybe_unused]], tg] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tf) == 2, ""); + static_assert (same_type <decltype (tf...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tf...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tg), short>::value, ""); + const auto & [th, ti, tj, ...tk] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (tk) == 0, ""); + static_assert (same_type <decltype (th), const int>::value, ""); + static_assert (same_type <decltype (ti), const long long>::value, ""); + static_assert (same_type <decltype (tj), const short>::value, ""); + auto [tl [[]], ...tm [[]], tn [[]]] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tm) == 1, ""); + static_assert (same_type <decltype (tl), int>::value, ""); + static_assert (same_type <decltype (tm...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tn), short>::value, ""); + auto && [...to] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (to) == 3, ""); + static_assert (same_type <decltype (to...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (to...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (to...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...tp, tq [[]], tr, ts] = T { 3, 1, 2 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tp) == 0, ""); + static_assert (same_type <decltype (tq), int>::value, ""); + static_assert (same_type <decltype (tr), long long>::value, ""); + static_assert (same_type <decltype (ts), short>::value, ""); + auto [tt, ...tu [[]], tv, tw] = T { 3, 1, 2 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tu) == 0, ""); + static_assert (same_type <decltype (tt), int>::value, ""); + static_assert (same_type <decltype (tv), long long>::value, ""); + static_assert (same_type <decltype (tw), short>::value, ""); + if (ta != 1 || tb != 2 || tc != 3 + || td != 1 || te...[0] != 2 || te...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || tf...[0] != 1 || tf...[1] != 2 || tg != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || th != 1 || ti != 2 || tj != 3 + || tl != 1 || tm...[0] != 2 || tn != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || to...[0] != 1 || to...[1] != 2 || to...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || tq != 1 || tr != 2 || ts != 3 + || tt != 1 || tv != 2 || tw != 3 + || sum (te...) != 5 + || sum <decltype (te)...> (te...) != 5 + || sum (square (square (te))...) != 97 + || sum (tf...) != 3 + || sum (tk...) != 0 + || sum (tm...) != 2 + || sum (to...) != 6 + || sum <decltype (to)...> (to...) != 6 + || sum (square (to)...) != 14 + || sum (tp...) != 0 + || sum (tu...) != 0 + || (te + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + tf) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + tk) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (tm + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (to + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (tp + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + tu) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + T t2[] = { { 3, 1, 2 }, { 6, 4, 5 }, { 9, 7, 8 } }; + i = 0; + for (auto [tx, ...ty] : t2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ty) == 2, ""); + static_assert (same_type <decltype (tx), int>::value, ""); + static_assert (same_type <decltype (ty...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ty...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (tx != i * 3 + 1 || sum (ty...) != i * 6 + 5) + __builtin_abort (); + auto fn1 = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; + fn1 (); + auto fn2 = [&ty..., &i] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn2 (); + auto fn3 = [&...ty2 = ty, &i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn3 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn4 = [&...ty3 = ref (ty), &i] () { if (sum (ty3...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn4 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn5 = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; + fn5 (); + auto fn6 = [ty..., i] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn6 (); + auto fn7 = [...ty2 = ty, i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn7 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn8 = [...ty3 = square (ty), i] () { if (sum (ty3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn8 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn9 = [&] () { auto fn = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; + fn9 (); + auto fn10 = [&ty..., &i] () { auto fn = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn10 (); + auto fn11 = [&] () { auto fn = [&...ty2 = ty, &i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn11 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn12 = [&ty..., &i] () { auto fn = [&...ty3 = ref (ty), &i] () { if (sum (ty3...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn12 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn13 = [=] () { auto fn = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; + fn13 (); + auto fn14 = [ty..., i] () { auto fn = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn14 (); + auto fn15 = [=] () { auto fn = [...ty2 = ty, i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn15 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn16 = [&ty..., &i] () { auto fn = [...ty3 = square (ty), i] () { if (sum (ty3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn16 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + ++i; + } + i = 0; + for (auto [...tz] : t2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (tz) == 3, ""); + static_assert (same_type <decltype (tz...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tz...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tz...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (tz...) != i * 9 + 6) + __builtin_abort (); + auto fn = [=] () { if (sum (tz...) != i * 9 + 6) __builtin_abort (); }; + fn (); + ++i; + } + if (auto [...tx [[maybe_unused]], ty] = t) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + __builtin_abort (); + else + { + static_assert (sizeof... (tx) == 2, ""); + static_assert (same_type <decltype (tx...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tx...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ty), short>::value, ""); + if (sum (tx...) != 3 || ty != 3) + __builtin_abort (); + } + int a[3] = { 1, 2, 3 }; + auto [aa, ab, ac] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (aa), int>::value, ""); + static_assert (same_type <decltype (ab), int>::value, ""); + static_assert (same_type <decltype (ac), int>::value, ""); + auto [ad [[maybe_unused]], ...ae [[maybe_unused]]] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ae) == 2, ""); + static_assert (same_type <decltype (ad), int>::value, ""); + static_assert (same_type <decltype (ae...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ae...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...af, ag] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (af) == 2, ""); + static_assert (same_type <decltype (af...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (af...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ag), int>::value, ""); + auto [ah, ai [[]], aj, ...ak [[]]] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ak) == 0, ""); + static_assert (same_type <decltype (ah), int>::value, ""); + static_assert (same_type <decltype (ai), int>::value, ""); + static_assert (same_type <decltype (aj), int>::value, ""); + auto [al, ...am [[]], an] = a;// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (am) == 1, ""); + static_assert (same_type <decltype (al), int>::value, ""); + static_assert (same_type <decltype (am...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (an), int>::value, ""); + const auto &[...ao] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ao) == 3, ""); + static_assert (same_type <decltype (ao...[0]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ao...[1]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ao...[2]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto &&[...ap, aq, ar [[]], as] = a;// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ap) == 0, ""); + static_assert (same_type <decltype (aq), int>::value, ""); + static_assert (same_type <decltype (ar), int>::value, ""); + static_assert (same_type <decltype (as), int>::value, ""); + auto [at, ...au, av, aw] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (au) == 0, ""); + static_assert (same_type <decltype (at), int>::value, ""); + static_assert (same_type <decltype (av), int>::value, ""); + static_assert (same_type <decltype (aw), int>::value, ""); + if (aa != 1 || ab != 2 || ac != 3 + || ad != 1 || ae...[0] != 2 || ae...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || af...[0] != 1 || af...[1] != 2 || ag != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || ah != 1 || ai != 2 || aj != 3 + || al != 1 || am...[0] != 2 || an != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || ao...[0] != 1 || ao...[1] != 2 || ao...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || aq != 1 || ar != 2 || as != 3 + || at != 1 || av != 2 || aw != 3 + || sum (ae...) != 5 + || sum <decltype (ae)...> (ae...) != 5 + || sum (square (square (ae))...) != 97 + || sum (af...) != 3 + || sum (ak...) != 0 + || sum (am...) != 2 + || sum (ao...) != 6 + || sum <decltype (ao)...> (ao...) != 6 + || sum (square (ao)...) != 14 + || sum (ap...) != 0 + || sum (au...) != 0 + || (ae + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + af) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + ak) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (am + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (ao + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (ap + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + au) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + return ses; +} + +int +main () +{ + if (foo <0> () != 2) + __builtin_abort (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp15.C b/gcc/testsuite/g++.dg/cpp26/decomp15.C new file mode 100644 index 0000000..9bb55b3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp15.C @@ -0,0 +1,474 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +struct S { + int a; long long b; short c; + explicit operator bool () const noexcept { return true; } +}; +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +struct T { + short c; int a; long long b; + template <int I> + typename std::tuple_element<I, T>::type &get (); + template <int I> + typename std::tuple_element<I, const T>::type &get () const; + explicit operator bool () const noexcept { return false; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 3; }; +template <> +struct std::tuple_element<0, T> { typedef int type; }; +template <> +struct std::tuple_element<1, T> { typedef long long type; }; +template <> +struct std::tuple_element<2, T> { typedef short type; }; +template <> +std::tuple_element<0, T>::type &T::get <0> () { return a; } +template <> +std::tuple_element<1, T>::type &T::get <1> () { return b; } +template <> +std::tuple_element<2, T>::type &T::get <2> () { return c; } +template <> +struct std::tuple_size<const T> { static constexpr int value = 3; }; +template <> +struct std::tuple_element<0, const T> { typedef const int type; }; +template <> +struct std::tuple_element<1, const T> { typedef const long long type; }; +template <> +struct std::tuple_element<2, const T> { typedef const short type; }; +template <> +std::tuple_element<0, const T>::type &T::get <0> () const { return a; } +template <> +std::tuple_element<1, const T>::type &T::get <1> () const { return b; } +template <> +std::tuple_element<2, const T>::type &T::get <2> () const { return c; } +template <typename T, typename U> +struct same_type { static const bool value = false; }; +template <typename T> +struct same_type<T, T> { static const bool value = true; }; + +int +sum () +{ + return 0; +} + +template <typename T, typename ...A> +T +sum (T x, A... y) +{ + return x + sum (y...); +} + +template <typename T> +T +square (T x) +{ + return x * x; +} + +template <typename T> +T & +ref (T &x) +{ + return x; +} + +using size_t = decltype (sizeof 0); + +template <typename S, typename T, typename U> +size_t +foo () +{ + S s = S { 1, 2, 3 }; + auto [sa, sb, sc] = S { 1, 2, 3 }; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (sa), int>::value, ""); + static_assert (same_type <decltype (sb), long long>::value, ""); + static_assert (same_type <decltype (sc), short>::value, ""); + auto [sd, ...se] = S { 1, 2, 3 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (se) == 2, ""); + static_assert (same_type <decltype (sd), int>::value, ""); + static_assert (same_type <decltype (se...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (se...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + const auto & [...sf [[]], sg] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sf) == 2, ""); + static_assert (same_type <decltype (sf...[0]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sf...[1]), const long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sg), const short>::value, ""); + auto [sh, si, sj [[]], ...sk] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sk) == 0, ""); + static_assert (same_type <decltype (sh), int>::value, ""); + static_assert (same_type <decltype (si), long long>::value, ""); + static_assert (same_type <decltype (sj), short>::value, ""); + auto && [sl, ...sm [[maybe_unused]], sn] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sm) == 1, ""); + static_assert (same_type <decltype (sl), int>::value, ""); + static_assert (same_type <decltype (sm...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sn), short>::value, ""); + auto [...so] = S { 1, 2, 3 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (so) == 3, ""); + static_assert (same_type <decltype (so...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (so...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (so...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...sp, sq, sr, ss [[maybe_unused]]] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sp) == 0, ""); + static_assert (same_type <decltype (sq), int>::value, ""); + static_assert (same_type <decltype (sr), long long>::value, ""); + static_assert (same_type <decltype (ss), short>::value, ""); + auto [st, ...su, sv, sw] = S { 1, 2, 3 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (su) == 0, ""); + static_assert (same_type <decltype (st), int>::value, ""); + static_assert (same_type <decltype (sv), long long>::value, ""); + static_assert (same_type <decltype (sw), short>::value, ""); + if (sa != 1 || sb != 2 || sc != 3 + || sd != 1 || se...[0] != 2 || se...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sf...[0] != 1 || sf...[1] != 2 || sg != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sh != 1 || si != 2 || sj != 3 + || sl != 1 || sm...[0] != 2 || sn != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || so...[0] != 1 || so...[1] != 2 || so...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sq != 1 || sr != 2 || ss != 3 + || st != 1 || sv != 2 || sw != 3 + || sum (se...) != 5 + || sum <decltype (se)...> (se...) != 5 + || sum (square (square (se))...) != 97 + || sum (sf...) != 3 + || sum (sk...) != 0 + || sum (sm...) != 2 + || sum (so...) != 6 + || sum <decltype (so)...> (so...) != 6 + || sum (square (so)...) != 14 + || sum (sp...) != 0 + || sum (su...) != 0 + || (se + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + sf) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + sk) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (sm + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (so + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (sp + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + su) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + S s2[] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; + int i = 0; + for (auto [sx, ...sy [[]]] : s2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (sy) == 2, ""); + static_assert (same_type <decltype (sx), int>::value, ""); + static_assert (same_type <decltype (sy...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sy...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sx != i * 3 + 1 || sum (sy...) != i * 6 + 5) + __builtin_abort (); + auto fn1 = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn1 (); + auto fn2 = [&sy..., &i] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn2 (); + auto fn3 = [&...sy2 = sy, &i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn3 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn4 = [&...sy3 = ref (sy), &i] () { if (sum (sy3...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn4 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn5 = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn5 (); + auto fn6 = [sy..., i] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn6 (); + auto fn7 = [...sy2 = sy, i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn7 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn8 = [...sy3 = square (sy), i] () { if (sum (sy3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn8 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn9 = [&] () { auto fn = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn9 (); + auto fn10 = [&sy..., &i] () { auto fn = [&] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn10 (); + auto fn11 = [&] () { auto fn = [&...sy2 = sy, &i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn11 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn12 = [&sy..., &i] () { auto fn = [&...sy3 = ref (sy), &i] () { if (sum (sy3...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn12 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn13 = [=] () { auto fn = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn13 (); + auto fn14 = [sy..., i] () { auto fn = [=] () { if (sum (sy...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn14 (); + auto fn15 = [=] () { auto fn = [...sy2 = sy, i] () { if (sum (sy2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn15 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn16 = [&sy..., &i] () { auto fn = [...sy3 = square (sy), i] () { if (sum (sy3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn16 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + ++i; + } + i = 0; + for (auto [...sz] : s2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (sz) == 3, ""); + static_assert (same_type <decltype (sz...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sz...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sz...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (sz...) != i * 9 + 6) + __builtin_abort (); + auto fn = [=] () { if (sum (sz...) != i * 9 + 6) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn (); + ++i; + } + if (auto [...sx, sy] = s) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + { + static_assert (sizeof... (sx) == 2, ""); + static_assert (same_type <decltype (sx...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sx...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (sy), short>::value, ""); + if (sum (sx...) != 3 || sy != 3) + __builtin_abort (); + } + else + __builtin_abort (); + T t = T { 3, 1, 2 }; + auto [ta, tb, tc] = T { 3, 1, 2 }; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (ta), int>::value, ""); + static_assert (same_type <decltype (tb), long long>::value, ""); + static_assert (same_type <decltype (tc), short>::value, ""); + auto [td [[maybe_unused]], ...te] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (te) == 2, ""); + static_assert (same_type <decltype (td), int>::value, ""); + static_assert (same_type <decltype (te...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (te...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...tf [[maybe_unused]], tg] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tf) == 2, ""); + static_assert (same_type <decltype (tf...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tf...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tg), short>::value, ""); + const auto & [th, ti, tj, ...tk] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (tk) == 0, ""); + static_assert (same_type <decltype (th), const int>::value, ""); + static_assert (same_type <decltype (ti), const long long>::value, ""); + static_assert (same_type <decltype (tj), const short>::value, ""); + auto [tl [[]], ...tm [[]], tn [[]]] = T { 3, 1, 2 }; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tm) == 1, ""); + static_assert (same_type <decltype (tl), int>::value, ""); + static_assert (same_type <decltype (tm...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tn), short>::value, ""); + auto && [...to] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (to) == 3, ""); + constexpr size_t tos = sizeof... (to); + static_assert (same_type <decltype (to...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (to...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (to...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...tp, tq [[]], tr, ts] = T { 3, 1, 2 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tp) == 0, ""); + static_assert (same_type <decltype (tq), int>::value, ""); + static_assert (same_type <decltype (tr), long long>::value, ""); + static_assert (same_type <decltype (ts), short>::value, ""); + auto [tt, ...tu [[]], tv, tw] = T { 3, 1, 2 };// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (tu) == 0, ""); + static_assert (same_type <decltype (tt), int>::value, ""); + static_assert (same_type <decltype (tv), long long>::value, ""); + static_assert (same_type <decltype (tw), short>::value, ""); + if (ta != 1 || tb != 2 || tc != 3 + || td != 1 || te...[0] != 2 || te...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || tf...[0] != 1 || tf...[1] != 2 || tg != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || th != 1 || ti != 2 || tj != 3 + || tl != 1 || tm...[0] != 2 || tn != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || to...[0] != 1 || to...[1] != 2 || to...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || tq != 1 || tr != 2 || ts != 3 + || tt != 1 || tv != 2 || tw != 3 + || sum (te...) != 5 + || sum <decltype (te)...> (te...) != 5 + || sum (square (square (te))...) != 97 + || sum (tf...) != 3 + || sum (tk...) != 0 + || sum (tm...) != 2 + || sum (to...) != 6 + || sum <decltype (to)...> (to...) != 6 + || sum (square (to)...) != 14 + || sum (tp...) != 0 + || sum (tu...) != 0 + || (te + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + tf) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + tk) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (tm + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (to + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (tp + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + tu) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + T t2[] = { { 3, 1, 2 }, { 6, 4, 5 }, { 9, 7, 8 } }; + i = 0; + for (auto [tx, ...ty] : t2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ty) == 2, ""); + static_assert (same_type <decltype (tx), int>::value, ""); + static_assert (same_type <decltype (ty...[0]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ty...[1]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (tx != i * 3 + 1 || sum (ty...) != i * 6 + 5) + __builtin_abort (); + auto fn1 = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; + fn1 (); + auto fn2 = [&ty..., &i] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn2 (); + auto fn3 = [&...ty2 = ty, &i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn3 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn4 = [&...ty3 = ref (ty), &i] () { if (sum (ty3...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn4 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn5 = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; + fn5 (); + auto fn6 = [ty..., i] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn6 (); + auto fn7 = [...ty2 = ty, i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn7 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn8 = [...ty3 = square (ty), i] () { if (sum (ty3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn8 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn9 = [&] () { auto fn = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; + fn9 (); + auto fn10 = [&ty..., &i] () { auto fn = [&] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn10 (); + auto fn11 = [&] () { auto fn = [&...ty2 = ty, &i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn11 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn12 = [&ty..., &i] () { auto fn = [&...ty3 = ref (ty), &i] () { if (sum (ty3...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn12 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + auto fn13 = [=] () { auto fn = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; + fn13 (); + auto fn14 = [ty..., i] () { auto fn = [=] () { if (sum (ty...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "captured structured bindings are" "" { target c++17_down } } + fn14 (); + auto fn15 = [=] () { auto fn = [...ty2 = ty, i] () { if (sum (ty2...) != i * 6 + 5) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn15 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + auto fn16 = [&ty..., &i] () { auto fn = [...ty3 = square (ty), i] () { if (sum (ty3...) != (i * 3 + 2) * (i * 3 + 2) + (i * 3 + 3) * (i * 3 + 3)) __builtin_abort (); }; fn (); }; // { dg-warning "pack init-capture only available with" "" { target c++17_down } } + fn16 (); // { dg-warning "lambda capture initializers only available with" "" { target c++11_only } .-1 } + // { dg-warning "captured structured bindings are" "" { target c++17_down } .-2 } + ++i; + } + i = 0; + for (auto [...tz] : t2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (tz) == 3, ""); + static_assert (same_type <decltype (tz...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tz...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tz...[2]), short>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (tz...) != i * 9 + 6) + __builtin_abort (); + auto fn = [=] () { if (sum (tz...) != i * 9 + 6) __builtin_abort (); }; + fn (); + ++i; + } + if (auto [...tx [[maybe_unused]], ty] = t) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + __builtin_abort (); + else + { + static_assert (sizeof... (tx) == 2, ""); + static_assert (same_type <decltype (tx...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (tx...[1]), long long>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ty), short>::value, ""); + if (sum (tx...) != 3 || ty != 3) + __builtin_abort (); + } + U a[3] = { 1, 2, 3 }; + auto [aa, ab, ac] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } } + static_assert (same_type <decltype (aa), int>::value, ""); + static_assert (same_type <decltype (ab), int>::value, ""); + static_assert (same_type <decltype (ac), int>::value, ""); + auto [ad [[maybe_unused]], ...ae [[maybe_unused]]] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ae) == 2, ""); + static_assert (same_type <decltype (ad), int>::value, ""); + static_assert (same_type <decltype (ae...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ae...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...af, ag] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (af) == 2, ""); + static_assert (same_type <decltype (af...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (af...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ag), int>::value, ""); + auto [ah, ai [[]], aj, ...ak [[]]] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ak) == 0, ""); + static_assert (same_type <decltype (ah), int>::value, ""); + static_assert (same_type <decltype (ai), int>::value, ""); + static_assert (same_type <decltype (aj), int>::value, ""); + auto [al, ...am [[]], an] = a;// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (am) == 1, ""); + static_assert (same_type <decltype (al), int>::value, ""); + static_assert (same_type <decltype (am...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (an), int>::value, ""); + const auto &[...ao] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ao) == 3, ""); + static_assert (same_type <decltype (ao...[0]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ao...[1]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ao...[2]), const int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto &&[...ap, aq, ar [[]], as] = a;// { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured bindings with attributed identifiers only available with" "" { target { c++17 && c++23_down } } .-2 } + static_assert (sizeof... (ap) == 0, ""); + static_assert (same_type <decltype (aq), int>::value, ""); + static_assert (same_type <decltype (ar), int>::value, ""); + static_assert (same_type <decltype (as), int>::value, ""); + auto [at, ...au, av, aw] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (au) == 0, ""); + static_assert (same_type <decltype (at), int>::value, ""); + static_assert (same_type <decltype (av), int>::value, ""); + static_assert (same_type <decltype (aw), int>::value, ""); + if (aa != 1 || ab != 2 || ac != 3 + || ad != 1 || ae...[0] != 2 || ae...[1] != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || af...[0] != 1 || af...[1] != 2 || ag != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || ah != 1 || ai != 2 || aj != 3 + || al != 1 || am...[0] != 2 || an != 3 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || ao...[0] != 1 || ao...[1] != 2 || ao...[2] != 3// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || aq != 1 || ar != 2 || as != 3 + || at != 1 || av != 2 || aw != 3 + || sum (ae...) != 5 + || sum <decltype (ae)...> (ae...) != 5 + || sum (square (square (ae))...) != 97 + || sum (af...) != 3 + || sum (ak...) != 0 + || sum (am...) != 2 + || sum (ao...) != 6 + || sum <decltype (ao)...> (ao...) != 6 + || sum (square (ao)...) != 14 + || sum (ap...) != 0 + || sum (au...) != 0 + || (ae + ...) != 5 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + af) != 3 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + ak) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (am + ... + 0) != 2 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (ao + ...) != 6 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (ap + ... + 0) != 0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + au) != 0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + return tos; +} + +int +main () +{ + if (foo <S, T, int> () != 3) + __builtin_abort (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp16.C b/gcc/testsuite/g++.dg/cpp26/decomp16.C new file mode 100644 index 0000000..548f9af --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp16.C @@ -0,0 +1,240 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +int +sum () +{ + return 0; +} + +template <typename T, typename ...A> +T +sum (T x, A... y) +{ + return x + sum (y...); +} + +template <typename T> +T +square (T x) +{ + return x * x; +} + +template <typename T, typename U> +struct same_type { static const bool value = false; }; + +template <typename T> +struct same_type<T, T> { static const bool value = true; }; + +typedef int V __attribute__((vector_size (16 * sizeof (int)))); + +template <int N> +void +foo () +{ + V v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + auto [...va] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (va) == 16, ""); + static_assert (same_type <decltype (va...[5]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (va...[13]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [vb, ...vc, vd, ve] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vc) == 13, ""); + static_assert (same_type <decltype (vb), int>::value, ""); + static_assert (same_type <decltype (vc...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vc...[12]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vd), int>::value, ""); + static_assert (same_type <decltype (ve), int>::value, ""); + auto [vf, vg, vh, vi, ...vj] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vj) == 12, ""); + static_assert (same_type <decltype (vf), int>::value, ""); + static_assert (same_type <decltype (vg), int>::value, ""); + static_assert (same_type <decltype (vh), int>::value, ""); + static_assert (same_type <decltype (vi), int>::value, ""); + static_assert (same_type <decltype (vj...[2]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vj...[10]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (va...[13] != 14 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (va...) != 8 * 17 + || sum (square (va)...) != 1496 + || vb != 1 + || vc...[10] != 12 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (vc...) != 15 * 7 - 1 + || sum <decltype (vc)...> (vc...) != 15 * 7 - 1 + || vd != 15 || ve != 16 + || vf != 1 || vg != 2 || vh != 3 || vi != 4 + || sum (vj...) != 8 * 17 - 10 + || (va + ...) != 8 * 17 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + vc) != 15 * 7 - 1 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + vj) != 8 * 17 - 10) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + V v2[3] = { v, v + 1, v + 2 }; + int i = 0; + for (auto [vk, ...vl, vm] : v2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vl) == 14, ""); + static_assert (same_type <decltype (vk), int>::value, ""); + static_assert (same_type <decltype (vl...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vl...[9]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vm), int>::value, ""); + if (vk != i + 1 || sum (vl...) != i * 14 + 15 * 8 - 1 || vm != i + 16) + __builtin_abort (); + ++i; + } + _Complex double c = 1.0 + 2.0i; + auto [...ca] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ca) == 2, ""); + static_assert (same_type <decltype (ca...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ca...[1]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [cb, ...cc, cd] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cc) == 0, ""); + static_assert (same_type <decltype (cb), double>::value, ""); + static_assert (same_type <decltype (cd), double>::value, ""); + auto [ce, ...cf] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cf) == 1, ""); + static_assert (same_type <decltype (ce), double>::value, ""); + static_assert (same_type <decltype (cf...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...cg, ch] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cg) == 1, ""); + static_assert (same_type <decltype (cg...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ch), double>::value, ""); + if (ca...[0] != 1.0 || ca...[1] != 2.0// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (ca...) != 3.0 + || sum <decltype (ca)...> (ca...) != 3.0 + || sum (square (square (square (ca)))...) != 257.0 + || cb != 1.0 || cd != 2.0 + || ce != 1.0 || cf...[0] != 2.0 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (cf...) != 2.0 + || cg...[0] != 1.0 || ch != 2.0 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (cg...) != 1.0 + || (ca + ...) != 3.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0.0 + ... + cc) != 0.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + cf) != 2.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (cg + ... + 0.0) != 1.0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + _Complex float c2[3] = { 1.0f + 2.0fi, 2.0f + 3.0fi, 3.0f + 4.0fi }; + i = 0; + for (auto [...ci] : c2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ci) == 2, ""); + static_assert (same_type <decltype (ci...[0]), float>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ci...[1]), float>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (ci...) != i * 2 + 3.0f) + __builtin_abort (); + ++i; + } +} + +template <typename V, typename C, typename D> +void +bar () +{ + V v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + auto [...va] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (va) == 16, ""); + static_assert (same_type <decltype (va...[5]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (va...[13]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [vb, ...vc, vd, ve] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vc) == 13, ""); + static_assert (same_type <decltype (vb), int>::value, ""); + static_assert (same_type <decltype (vc...[0]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vc...[12]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vd), int>::value, ""); + static_assert (same_type <decltype (ve), int>::value, ""); + auto [vf, vg, vh, vi, ...vj] = v; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vj) == 12, ""); + static_assert (same_type <decltype (vf), int>::value, ""); + static_assert (same_type <decltype (vg), int>::value, ""); + static_assert (same_type <decltype (vh), int>::value, ""); + static_assert (same_type <decltype (vi), int>::value, ""); + static_assert (same_type <decltype (vj...[2]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vj...[10]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (va...[13] != 14 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (va...) != 8 * 17 + || vb != 1 + || vc...[10] != 12 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (vc...) != 15 * 7 - 1 + || sum <decltype (vc)...> (vc...) != 15 * 7 - 1 + || vd != 15 || ve != 16 + || vf != 1 || vg != 2 || vh != 3 || vi != 4 + || sum (vj...) != 8 * 17 - 10 + || (va + ...) != 8 * 17 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + vc) != 15 * 7 - 1 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0 + ... + vj) != 8 * 17 - 10) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + V v2[3] = { v, v + 1, v + 2 }; + int i = 0; + for (auto [vk, ...vl, vm] : v2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (vl) == 14, ""); + static_assert (same_type <decltype (vk), int>::value, ""); + static_assert (same_type <decltype (vl...[1]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vl...[9]), int>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (vm), int>::value, ""); + if (vk != i + 1 || sum (vl...) != i * 14 + 15 * 8 - 1 || vm != i + 16) + __builtin_abort (); + ++i; + } + C c = 1.0 + 2.0i; + auto [...ca] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ca) == 2, ""); + static_assert (same_type <decltype (ca...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ca...[1]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [cb, ...cc, cd] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cc) == 0, ""); + static_assert (same_type <decltype (cb), double>::value, ""); + static_assert (same_type <decltype (cd), double>::value, ""); + auto [ce, ...cf] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cf) == 1, ""); + static_assert (same_type <decltype (ce), double>::value, ""); + static_assert (same_type <decltype (cf...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + auto [...cg, ch] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (cg) == 1, ""); + static_assert (same_type <decltype (cg...[0]), double>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ch), double>::value, ""); + if (ca...[0] != 1.0 || ca...[1] != 2.0// { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (ca...) != 3.0 + || sum <decltype (ca)...> (ca...) != 3.0 + || cb != 1.0 || cd != 2.0 + || ce != 1.0 || cf...[0] != 2.0 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (cf...) != 2.0 + || cg...[0] != 1.0 || ch != 2.0 // { dg-warning "pack indexing only available with" "" { target c++23_down } } + || sum (cg...) != 1.0 + || (ca + ...) != 3.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (0.0 + ... + cc) != 0.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (... + cf) != 2.0 // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + || (cg + ... + 0.0) != 1.0) // { dg-warning "fold-expressions only available with" "" { target c++14_down } } + __builtin_abort (); + D c2[3] = { 1.0f + 2.0fi, 2.0f + 3.0fi, 3.0f + 4.0fi }; + i = 0; + for (auto [...ci] : c2) // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + { // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ci) == 2, ""); + static_assert (same_type <decltype (ci...[0]), float>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + static_assert (same_type <decltype (ci...[1]), float>::value, ""); // { dg-warning "pack indexing only available with" "" { target c++23_down } } + if (sum (ci...) != i * 2 + 3.0f) + __builtin_abort (); + ++i; + } +} + +int +main () +{ + foo <0> (); + bar <V, _Complex double, _Complex float> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp17.C b/gcc/testsuite/g++.dg/cpp26/decomp17.C new file mode 100644 index 0000000..49ad0e2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp17.C @@ -0,0 +1,28 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do compile { target c++11 } } +// { dg-options "" } + +typedef int V __attribute__((vector_size (16 * sizeof (int)))); + +template <int N> +void +foo () +{ + V v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + auto [va, vb, vc, vd, ...ve, vf, vg, vh, vi, vj, vk, vl, vm, vn, vo, vp, vq, vr] = v; + // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } .-1 } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-2 } + // { dg-error "18 names provided for structured binding" "" { target *-*-* } .-3 } + // { dg-message "while '__vector\\\(16\\\) int' decomposes into 16 elements" "" { target *-*-* } .-4 } + _Complex double c = 1.0 + 2.0i; + auto [...ca, cb, cc, cd] = c; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-error "4 names provided for structured binding" "" { target *-*-* } .-2 } + // { dg-message "while '__complex__ double' decomposes into 2 elements" "" { target *-*-* } .-3 } +} + +int +main () +{ + foo <0> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp18.C b/gcc/testsuite/g++.dg/cpp26/decomp18.C new file mode 100644 index 0000000..86b9bf4 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp18.C @@ -0,0 +1,109 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +struct S { int a, b, c; }; +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +struct T { + int a[3]; + template <int I> + int &get () { return a[2 - I]; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 3; }; +template <int N> +struct std::tuple_element<N, T> { typedef int type; }; + +template <int N> +inline int +foo () +{ + static int a[4] = { N, N + 1, N + 2, N + 3 }; + static auto [...aa] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 } + aa...[1]++; // { dg-warning "pack indexing only available with" "" { target c++23_down } } + return (... + aa); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +bar () +{ + static S s = { N, N + 1, N + 2 }; + static auto [...sa] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 } + sa...[1]++; // { dg-warning "pack indexing only available with" "" { target c++23_down } } + return (sa + ...); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +baz () +{ + static T t = { { N, N + 1, N + 2 } }; + static auto [ta, ...tb, tc, td] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 } + tc++; + return ((ta + tc + td) + ... + tb); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +qux () +{ + thread_local int a[4] = { N, N + 1, N + 2, N + 3 }; + thread_local auto [...aa] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } .-2 } + aa...[1]++; // { dg-warning "pack indexing only available with" "" { target c++23_down } } + return (... + aa); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +freddy () +{ + thread_local S s = { N, N + 1, N + 2 }; + thread_local auto [...sa] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } .-2 } + sa...[1]++; // { dg-warning "pack indexing only available with" "" { target c++23_down } } + return (sa + ...); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +template <int N> +inline int +corge () +{ + thread_local T t = { { N, N + 1, N + 2 } }; + thread_local auto [ta, ...tb, tc, td] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } .-2 } + tc++; + return ((ta + tc + td) + ... + tb); // { dg-warning "fold-expressions only available with" "" { target c++14_down } } +} + +int +main () +{ + if (foo <2> () != 15 || foo <2> () != 16 || foo <2> () != 17 + || foo <42> () != 175 || foo <42> () != 176 + || bar <5> () != 19 || bar <5> () != 20 || bar <5> () != 21 + || bar <18> () != 58 || bar <18> () != 59 + || baz <3> () != 13 || baz <3> () != 14 || baz <3> () != 15 + || baz <22> () != 70 || baz <22> () != 71) + __builtin_abort (); + if (qux <2> () != 15 || qux <2> () != 16 || qux <2> () != 17 + || qux <42> () != 175 || qux <42> () != 176 + || freddy <5> () != 19 || freddy <5> () != 20 || freddy <5> () != 21 + || freddy <18> () != 58 || freddy <18> () != 59 + || corge <3> () != 13 || corge <3> () != 14 || corge <3> () != 15 + || corge <22> () != 70 || corge <22> () != 71) + __builtin_abort (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp19.C b/gcc/testsuite/g++.dg/cpp26/decomp19.C new file mode 100644 index 0000000..b4d97a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp19.C @@ -0,0 +1,46 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do compile { target c++11 } } +// { dg-options "" } + +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +struct T { + int a[3]; + template <int I> + int &get () { return a[2 - I]; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 3; }; +template <int N> +struct std::tuple_element<N, T> { typedef int type; }; + +template <int N> +inline void +foo () +{ + static T t = { { N, N + 1, N + 2 } }; + static auto [ta, ...tb, tc] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'static' only in" "" { target c++17_down } .-2 } + // { dg-message "mangling of structured binding pack elements not implemented yet" "" { target *-*-* } .-3 } +} + +template <int N> +inline void +bar () +{ + thread_local T t = { { N, N + 1, N + 2 } }; + thread_local auto [...ta] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + // { dg-warning "structured binding declaration can be 'thread_local' only in" "" { target c++17_down } .-2 } + // { dg-message "mangling of structured binding pack elements not implemented yet" "" { target *-*-* } .-3 } +} + +int +main () +{ + foo <0> (); + bar <0> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp20.C b/gcc/testsuite/g++.dg/cpp26/decomp20.C new file mode 100644 index 0000000..5091e13 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp20.C @@ -0,0 +1,53 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do compile { target c++11 } } +// { dg-options "" } + +struct S { + explicit operator bool () const noexcept { return true; } +}; +namespace std { + template <typename T> struct tuple_size; + template <int, typename> struct tuple_element; +} +int x; +struct T { + template <int I> + int &get () { return x; } + explicit operator bool () const noexcept { return false; } +}; +template <> +struct std::tuple_size<T> { static constexpr int value = 0; }; +template <int N> +struct std::tuple_element<N, T> { typedef int type; }; + +template <int N> +void +foo () +{ + int a[0] = {}; + auto [...aa] = a; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (aa) == 0, ""); + S s = {}; + auto [...sa] = s; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (sa) == 0, ""); + T t = {}; + auto [...ta] = t; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (ta) == 0, ""); + if (auto [...sb] = s) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + static_assert (sizeof... (sb) == 0, ""); + else + __builtin_abort (); + if (auto [...tb] = t) // { dg-warning "structured bindings in conditions only available with" "" { target c++23_down } } + __builtin_abort (); + else + static_assert (sizeof... (tb) == 0, ""); +} + +int +main () +{ + foo <0> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/decomp21.C b/gcc/testsuite/g++.dg/cpp26/decomp21.C new file mode 100644 index 0000000..6baa8aa --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp26/decomp21.C @@ -0,0 +1,103 @@ +// P1061R10 - Structured Bindings can introduce a Pack +// { dg-do run { target c++11 } } +// { dg-options "" } + +using size_t = decltype (sizeof 0); + +auto g () -> int (&)[4] +{ + static int a[4] = { 1, 2, 3, 4 }; + return a; +} + +template <size_t N> +void +h (int (&arr)[N]) +{ + auto [a, ...b, c] = arr; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (b) == 2, ""); + auto &[f, ...g, h] = arr; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (g) == 2, ""); + if (&f != &arr[0] || &h != &arr[3] + || &g...[0] != &arr[1] || &g...[1] != &arr[2]) // { dg-warning "pack indexing only available with" "" { target c++23_down } } + __builtin_abort (); + auto &[...e] = arr; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof ... (e) == 4, ""); + if (&e...[0] != &arr[0] || &e...[3] != &arr[3]) // { dg-warning "pack indexing only available with" "" { target c++23_down } } + __builtin_abort (); +} + +struct C { int x, y, z; }; + +template <class T> +void +now_i_know_my () +{ + auto [a, b, c] = C (); // { dg-warning "structured bindings only available with" "" { target c++14_down } } + auto [d, ...e] = C (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (e) == 2, ""); + auto [...f, g] = C (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (f) == 2, ""); + auto [h, i, j, ...k] = C (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (k) == 0, ""); +// auto [l, m, n, o, ...p] = C (); +} + +auto foo () -> int (&)[2] +{ + static int a[2] = { 1, 2 }; + return a; +} + +template <class T> +void +bar () +{ + auto [...a] = foo (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (a) == 2, ""); + auto [b, c, ...d] = foo (); // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + static_assert (sizeof... (d) == 0, ""); +} + +struct D { }; + +void +baz (...) +{ + __builtin_abort (); +} + +template <typename T> +void +qux () +{ + D arr[1] = {}; + auto [...e] = arr; // { dg-warning "structured binding packs only available with" "" { target { c++17 && c++23_down } } } + // { dg-warning "structured bindings only available with" "" { target c++14_down } .-1 } + baz (e...); +} + +int d; + +void +baz (D) +{ + d = 1; +} + +int +main () +{ + h (g ()); + now_i_know_my <int> (); + bar <int> (); + qux <int> (); +} diff --git a/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C b/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C index cfc5f61..9284bc2 100644 --- a/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C +++ b/gcc/testsuite/g++.dg/cpp26/feat-cxx26.C @@ -395,8 +395,8 @@ #ifndef __cpp_structured_bindings # error "__cpp_structured_bindings" -#elif __cpp_structured_bindings != 202403 -# error "__cpp_structured_bindings != 202403" +#elif __cpp_structured_bindings != 202411 +# error "__cpp_structured_bindings != 202411" #endif #ifndef __cpp_template_template_args diff --git a/gcc/testsuite/g++.dg/modules/class-11_a.H b/gcc/testsuite/g++.dg/modules/class-11_a.H index 799dbdd..43fddb6 100644 --- a/gcc/testsuite/g++.dg/modules/class-11_a.H +++ b/gcc/testsuite/g++.dg/modules/class-11_a.H @@ -1,6 +1,7 @@ // Check for some additional lang_type flags that we'd missed. // { dg-additional-options "-fmodule-header -fabi-version=21 -Wabi=15" } // { dg-module-cmi {} } +// { dg-skip-if "test assumes that structs have padding" { default_packed } } #if __cpp_trivial_relocatability < 202502L #define trivially_relocatable_if_eligible __trivially_relocatable_if_eligible diff --git a/gcc/testsuite/g++.dg/modules/class-11_b.C b/gcc/testsuite/g++.dg/modules/class-11_b.C index 2450a45..87be71a 100644 --- a/gcc/testsuite/g++.dg/modules/class-11_b.C +++ b/gcc/testsuite/g++.dg/modules/class-11_b.C @@ -1,4 +1,5 @@ // { dg-additional-options "-fmodules -fabi-version=21 -Wabi=15" } +// { dg-skip-if "test assumes that structs have padding" { default_packed } } import "class-11_a.H"; diff --git a/gcc/testsuite/g++.dg/torture/noncall-eh-1.C b/gcc/testsuite/g++.dg/torture/noncall-eh-1.C new file mode 100644 index 0000000..ea8fd79 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/noncall-eh-1.C @@ -0,0 +1,26 @@ +// { dg-do compile } +// For slim LTO there's no optimized dump +// { dg-skip-if "" { *-*-* } { "-flto" } { "" } } +// { dg-additional-options "-fnon-call-exceptions -fexceptions -fdump-tree-optimized-eh" } + +// PR tree-optimization/120599 +// Copying prop for aggregates should not touch `a = *__val` since that statement +// can throw (internally) so we need to be able to keep the landing pad. + +struct RefitOption { + char subtype; + int string; +} n; +void h(RefitOption) __attribute__((nothrow)); +void k(RefitOption *__val, RefitOption a) +{ + try { + a = *__val; + RefitOption __trans_tmp_2 = a; + h(__trans_tmp_2); + } + catch(...){} +} + +// Make sure There is a landing pad for the non-call exception from the aggregate load. +// { dg-final { scan-tree-dump "LP " "optimized" } } diff --git a/gcc/testsuite/g++.target/aarch64/sve/pr121449.C b/gcc/testsuite/g++.target/aarch64/sve/pr121449.C new file mode 100644 index 0000000..b2e1376 --- /dev/null +++ b/gcc/testsuite/g++.target/aarch64/sve/pr121449.C @@ -0,0 +1,44 @@ +/* PR target/121449 */ +/* { dg-do assemble { target aarch64_asm_sve_ok } } */ +/* { dg-options "-O3 -save-temps" } */ + +struct example; + +struct array { + unsigned length(); + example *operator[](unsigned i) { + example **data = reinterpret_cast<example **>(this); + return data[i]; + } +}; + +struct example { + int a[16]; + bool is_even; + int version; + int count() { return is_even ? 2 : 1; } + void fun1(int, long); + void fun2(unsigned, unsigned); + void process(array &, array &); +}; + +bool found; + +void example::process(array &a, array &b) { + for (unsigned i = 1; a.length(); i++) { + long total = 0; + for (unsigned k = 0; k <= i; k++) { + total += a[k]->count(); + } + for (unsigned j = 0; j < i; j++) { + int major = b[j]->version; + if (found) + major += i; + fun1(i + 1, total); + fun2(j, major); + } + } +} + +/* { dg-final { scan-assembler-not {\tld1b\t(z[0-9]+)\.d, p[0-7]/z, \[(z[0-9]+)\.d, #64\]} } } */ + diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c new file mode 100644 index 0000000..3492899 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-no-show-nesting.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ +/* { dg-options "-fno-diagnostics-show-nesting" } */ + +extern void foo (void); + +void test_nesting (void) +{ + foo (); /* { dg-error "top-level error" } */ +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c new file mode 100644 index 0000000..8fc2edb --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-show-nesting.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-fdiagnostics-show-nesting" } */ + +extern void foo (void); + +void test_nesting (void) +{ + foo (); /* { dg-error "top-level error" } */ +} + +/* { dg-begin-multiline-output "" } + * child 0 + * grandchild 0 0 + * grandchild 0 1 + * grandchild 0 2 + * child 1 + * grandchild 1 0 + * grandchild 1 1 + * grandchild 1 2 + * child 2 + * grandchild 2 0 + * grandchild 2 1 + * grandchild 2 2 + { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c index f44c8eb..4be52fe 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-show-levels.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-set-output=text:experimental-nesting=yes,experimental-nesting-show-levels=yes" } */ +/* { dg-options "-fdiagnostics-set-output=text:show-nesting=yes,show-nesting-levels=yes" } */ extern void foo (void); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c index 39e29f7..c069c3f 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented-unicode.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-set-output=text:experimental-nesting=yes -fdiagnostics-text-art-charset=unicode" } */ +/* { dg-options "-fdiagnostics-set-output=text:show-nesting=yes -fdiagnostics-text-art-charset=unicode" } */ extern void foo (void); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c index e103429..a35254d 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-nesting-text-indented.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-fdiagnostics-set-output=text:experimental-nesting=yes" } */ +/* { dg-options "-fdiagnostics-set-output=text:show-nesting=yes" } */ extern void foo (void); diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index 3bb6063..c7cc36c 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -112,6 +112,8 @@ set plugin_test_list [list \ diagnostic-test-graphs-html.c \ diagnostic-test-graphs-sarif.c } \ { diagnostic_plugin_test_nesting.cc \ + diagnostic-test-nesting-show-nesting.c \ + diagnostic-test-nesting-no-show-nesting.c \ diagnostic-test-nesting-text-plain.c \ diagnostic-test-nesting-text-indented.c \ diagnostic-test-nesting-text-indented-show-levels.c \ diff --git a/gcc/testsuite/gcc.dg/pr118946-1.c b/gcc/testsuite/gcc.dg/pr118946-1.c new file mode 100644 index 0000000..6cf2661 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr118946-1.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized -fdump-tree-forwprop1-details" } */ + +/* PR tree-optimization/118946 */ + +void f(char *a) +{ + char t[1024] = {}; + __builtin_memcpy(a, t, 10); +} + +/* We should be able to optimize the memcpy into a memset here. */ +/* { dg-final { scan-tree-dump-times "after previous" 1 "forwprop1"} } */ +/* { dg-final { scan-tree-dump-times "memset " 1 "optimized" } } */ +/* { dg-final { scan-tree-dump-not "memcpy " "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/torture/hardbool-ai.c b/gcc/testsuite/gcc.dg/torture/hardbool-ai.c index 97569a6..af4e0e1 100644 --- a/gcc/testsuite/gcc.dg/torture/hardbool-ai.c +++ b/gcc/testsuite/gcc.dg/torture/hardbool-ai.c @@ -1,4 +1,5 @@ /* { dg-do run } */ +/* { dg-require-effective-target sync_int_long } */ #define basetype _Atomic int diff --git a/gcc/testsuite/gcc.dg/torture/pr121422-1.c b/gcc/testsuite/gcc.dg/torture/pr121422-1.c new file mode 100644 index 0000000..136f80d --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121422-1.c @@ -0,0 +1,35 @@ +/* { dg-do run } */ +/* PR tree-optimization/121422 */ + +struct s1 +{ + char a[4]; +}; +struct s1 b; +char t[4]; + +/* if both t and b startout zero initialized before this function, + t should end up being: + {0, 0, 1, 0} + while b.a should end up being: + {0, 0, 0, 1} +*/ +__attribute__((noipa,noinline)) +void f(void) +{ + b = (struct s1){}; + b.a[3] = 1; + /* This memcpy should stay a memcpy and not become memset. */ + __builtin_memcpy(&t[0], &b.a[1], 3*sizeof(t[0])); +} + + +int main() +{ + f(); + for(int i = 0; i < 4; i++) + { + if (t[i] != (i == 2 ? 1 : 0)) + __builtin_abort(); + } +} diff --git a/gcc/testsuite/gcc.dg/torture/pr121422-2.c b/gcc/testsuite/gcc.dg/torture/pr121422-2.c new file mode 100644 index 0000000..570559c --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr121422-2.c @@ -0,0 +1,36 @@ +/* { dg-do run } */ +/* PR tree-optimization/121422 */ + +struct s1 +{ + char a[4]; +}; +struct s1 b; +char t[4]; + +/* if both t and b startout zero initialized before this function, + t should end up being: + {0, 0, 1, 0} + while b.a should end up being: + {0, 0, 0, 1} +*/ +__attribute__((noipa,noinline)) +void f(void) +{ + __builtin_memset(&b.a[1], 0, 2); + b.a[3] = 1; + /* This memcpy should stay a memcpy and not become memset. */ + __builtin_memcpy(&t[0], &b.a[1], 3); +} + + +int main() +{ + f(); + for(int i = 0; i < 4; i++) + { + if (t[i] != (i == 2 ? 1 : 0)) + __builtin_abort(); + } +} + diff --git a/gcc/testsuite/gcc.target/aarch64/pr120986-1.c b/gcc/testsuite/gcc.target/aarch64/pr120986-1.c new file mode 100644 index 0000000..e3bc56c --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/pr120986-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=armv8.2-a+sve2+fp8dot2" } */ +#include <arm_sve.h> + +/* This triggered an ICE with an unrecognizable insn due to incorrect gating of + the insn in the backend. */ +svfloat16_t foo(svfloat16_t a, svmfloat8_t b, svmfloat8_t c, unsigned long fpm) +{ + return svdot_lane_fpm (a, b, c, 0, fpm); +} diff --git a/gcc/testsuite/gcc.target/aarch64/sme/pr121414_1.c b/gcc/testsuite/gcc.target/aarch64/sme/pr121414_1.c new file mode 100644 index 0000000..ad8600f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sme/pr121414_1.c @@ -0,0 +1,27 @@ +#pragma GCC target "+sme2" + +void f1() __arm_streaming_compatible {} +void f2() __arm_streaming {} +void f3() __arm_in("za") {} +void f4() __arm_out("za") {} +void f5() __arm_inout("za") {} +void f6() __arm_in("zt0") {} +void f7() __arm_out("zt0") {} +void f8() __arm_inout("zt0") {} + +__arm_locally_streaming void g1() {} +__arm_new("za") void g2() {} +__arm_new("zt0") void g3() {} + +/* { dg-final { scan-assembler {\t\.variant_pcs\tf1\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf2\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf3\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf4\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf5\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf6\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf7\n} } } */ +/* { dg-final { scan-assembler {\t\.variant_pcs\tf8\n} } } */ + +/* { dg-final { scan-assembler-not {\t\.variant_pcs\tg1\n} } } */ +/* { dg-final { scan-assembler-not {\t\.variant_pcs\tg2\n} } } */ +/* { dg-final { scan-assembler-not {\t\.variant_pcs\tg3\n} } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr120718.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr120718.c new file mode 100644 index 0000000..9ca0938 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/pr120718.c @@ -0,0 +1,12 @@ +/* { dg-options "-O2" } */ + +#include <arm_sve.h> +typedef int __attribute__((vector_size(8))) v2si; +typedef struct { int x; int y; } A; +void bar(A a); +void foo() +{ + A a; + *(v2si *)&a = (v2si){0, (int)svcntd_pat(SV_ALL)}; + bar(a); +} diff --git a/gcc/testsuite/gcc.target/aarch64/torture/pr120986-2.c b/gcc/testsuite/gcc.target/aarch64/torture/pr120986-2.c new file mode 100644 index 0000000..1218dea --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/torture/pr120986-2.c @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-march=armv8.2-a+sve2+fp8dot2" } */ +#include <arm_sve.h> +svfloat16_t foo(svfloat16_t a, svmfloat8_t b, svmfloat8_t c) +{ + return svdot_lane_fpm (a, b, c, 0, 0); +} diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-18.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-18.c index db7d975..eb8a358 100644 --- a/gcc/testsuite/gcc.target/arm/cmse/cmse-18.c +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-18.c @@ -1,5 +1,6 @@ /* { dg-do compile } */ -/* { dg-options "-mcmse -fdump-rtl-final-slim" } */ +/* Make sure FPCXT is not enabled. */ +/* { dg-options "-mcmse -fdump-rtl-final -march=armv8-m.main+fp" } */ typedef void (*f)(int) __attribute__((cmse_nonsecure_call)); @@ -8,5 +9,5 @@ void bar(f func, int a) func(a); } -/* { dg-final { scan-rtl-dump "call unspec\\\[\\\[r4:SI\\\]\\\]" "final" { target { ! arm_v8_1m_mve_ok } } } } */ -/* { dg-final { scan-rtl-dump "call unspec\\\[\\\[r\[0-7\]:SI\\\]\\\]" "final" { target { arm_v8_1m_mve_ok } } } } */ +/* { dg-final { scan-rtl-dump "call \\\(mem:SI \\\(reg:SI 4 r4" "final" } } */ +/* { dg-final { scan-rtl-dump "UNSPEC_NONSECURE_MEM" "final" } } */ diff --git a/gcc/testsuite/gcc.target/arm/cmse/cmse-19.c b/gcc/testsuite/gcc.target/arm/cmse/cmse-19.c new file mode 100644 index 0000000..ae075c3 --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/cmse/cmse-19.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* This is a duplicate of cmse-18.c, targetting arm_v8_1m_mve, to make sure + FPCXT is enabled. */ +/* { dg-options "-mcmse -fdump-rtl-final -march=armv8.1-m.main+mve" } */ + +typedef void (*f)(int) __attribute__((cmse_nonsecure_call)); + +void bar(f func, int a) +{ + func(a); +} + +/* { dg-final { scan-rtl-dump "call \\\(mem:SI \\\(reg/f:SI \[0-7] r\[0-7\]" "final" } } */ +/* { dg-final { scan-rtl-dump "UNSPEC_NONSECURE_MEM" "final" } } */ diff --git a/gcc/testsuite/gcc.target/i386/asm-hard-reg-2.c b/gcc/testsuite/gcc.target/i386/asm-hard-reg-2.c index b35cf53..756f6f8 100644 --- a/gcc/testsuite/gcc.target/i386/asm-hard-reg-2.c +++ b/gcc/testsuite/gcc.target/i386/asm-hard-reg-2.c @@ -8,7 +8,7 @@ test (void) #ifdef __x86_64__ int z __attribute__ ((mode (TI))); #else - long z; + long long z; #endif __asm__ __volatile__ ("" : "=A" (z), "={rbx}" (y)); diff --git a/gcc/testsuite/gfortran.dg/generic_stmt_1.f90 b/gcc/testsuite/gfortran.dg/generic_stmt_1.f90 new file mode 100644 index 0000000..57d0aba --- /dev/null +++ b/gcc/testsuite/gfortran.dg/generic_stmt_1.f90 @@ -0,0 +1,194 @@ +! { dg-do run } +! +! Test the F2018 generic statement +! +function cg (arg1, arg2) + complex :: cg + complex, intent(in) :: arg1, arg2 + cg = arg1 + arg2 +end + +module m + implicit none + + type :: t + integer :: i + end type + integer :: tsum = 0 + + public g + interface g ! Check generic statement + generic interface works + module procedure tg + end interface g + + generic :: g => ig, rg + generic :: operator(.plus.) => ig, rg + generic, private :: h => ig, rg + generic :: WRITE(FORMATTED) => wtarray + + interface g ! Check generic statement + generic interface works + function cg (arg1, arg2) + complex :: cg + complex, intent(in) :: arg1, arg2 + end + end interface g + +! Subroutines + generic, public :: sg => sig, srg + +! Check that we can mix with submodule procedures + interface + real module function realg (arg1, arg2) + real, intent(in) :: arg1, arg2 + end function + end interface + generic, public :: subg => ig, realg + +contains + + function rg (arg1, arg2) + real :: rg + real, intent(in) :: arg1, arg2 + rg = arg1 + arg2 + end + function ig (arg1, arg2) + integer :: ig + integer, intent(in) :: arg1, arg2 + ig = arg1 + arg2 + end + function tg (arg1, arg2) result(res) + type(t) :: res + type(t), intent(in) :: arg1, arg2 + res%i = arg1%i + arg2%i + end + subroutine srg (arg1, arg2, arg3) + real :: arg3 + real, intent(in) :: arg1, arg2 + arg3 = arg1 + arg2 + end + subroutine sig (arg1, arg2, arg3) + integer :: arg3 + integer, intent(in) :: arg1, arg2 + arg3 = arg1 + arg2 + end + + SUBROUTINE wtarray (dtv, unit, iotype, v_list, iostat, iomsg) + CLASS(t), INTENT(IN) :: dtv + INTEGER, INTENT(IN) :: unit + CHARACTER(*), INTENT(IN) :: iotype + INTEGER, INTENT(IN) :: v_list (:) + INTEGER, INTENT(OUT) :: iostat + CHARACTER(*), INTENT(INOUT) :: iomsg + WRITE (unit, FMT=*, iostat=iostat, iomsg=iomsg) dtv%i + END SUBROUTINE wtarray + + subroutine foo + real :: a = 1.0, b = 2.0, r + integer :: c = 3, d = 4 + type(t) :: tres + generic :: operator(+) => tg +! private in foo + r = h(a,b) + if (r /= rg(a,b)) stop 1 + if (h(c,d) /= ig(c,d)) stop 2 +! operator in foo + r = a.plus.b + if (r /= rg(a,b)) stop 3 + if ((c.plus.(2*d)) /= ig(c,2*d)) stop 4 +! check intrinsic operator + tres = t(21) + t(21) + if (tres%i /= 42) stop 5 + end +end module m + +submodule (m) subm +contains + real module function realg (arg1, arg2) + real, intent(in) :: arg1, arg2 + realg = arg1 + arg2 + end +end + +program p + use m + implicit none + integer :: i, rv + + generic :: operator(.minus.) => pig, prg + generic :: operator(*) => times + generic :: j => ig, rg + generic :: j => mg + + real :: a = 1.0, b = 2.0, s3 + integer :: c = 3, d = 4, si + type(t) :: t1 = t(2), t2 = t(3), tres + type(t) :: tarray(5) = [t(5), t(4), t(3), t(2), t(1)] + +! module generic in p + if (g(2.0*a,2.0*b) /= rg(2.0*a,2.0*b)) stop 6 + if (g(c,d) /= ig(c,d)) stop 7 +! local generic in p + if (j(a,b) /= rg(a,b)) stop 8 + if (j(c,d) /= ig (c,d)) stop 9 +! local generic in p with different number of arguments + if (j(c,d,-1) /= mg(c,d,-1)) stop 10 +! module operator in p + if (7*int(a.plus.b) /= 3*(c.plus.d)) stop 11 +! local operator in p + if ((a.minus.b) /= prg(a,b)) stop 12 + if ((c.minus.d) /= pig(c,d)) stop 13 +! local operator in block + block + generic :: operator(.bminus.) => pig, prg + if ((a.bminus.b) /= prg(a,b)) stop 14 + if ((c.bminus.d) /= pig(c,d)) stop 15 + end block +! intrinsic operator in p + tres = t1 * t2 + if (tres%i /= 6) stop 16 +! test private interface in module + call foo +! test mixture of GENERIC statement and generic INTERFACE + if (g((1.0,1.0),(2.0,2.0)) /= cg((1.0,1.0),(2.0,2.0))) stop 17 + tres = g(t1,t2) + if (tres%i /= 5) stop 18 +! subroutines + call sg(10.0*a, b, s3) + if (int(s3) /= 12) stop 19 + call sg(5*c, d, si) + if (si /= 19) stop 20 +! submodule procedures + if (subg(20.0*a,2.0*b) /= realg(20.0*a,2.0*b)) stop 21 +! check DTIO + open (10,status='scratch') + WRITE(10, '(DT)') tarray + rewind(10) + do i = 1,5 + read(10, *) rv + tsum = tsum + rv + end do + close(10) + if (tsum /= 15) stop 22 +contains + + function pig (arg1, arg2) + integer :: pig + integer, intent(in) :: arg1, arg2 + pig = arg1 - arg2 + end + function prg (arg1, arg2) + real :: prg + real, intent(in) :: arg1, arg2 + prg = arg1 - arg2 + end + function times (arg1, arg2) result(res) + type(t) :: res + type(t), intent(in) :: arg1, arg2 + res%i = arg1%i * arg2%i + end + function mg (arg1, arg2, arg3) + integer :: mg + integer, intent(in) :: arg1, arg2, arg3 + mg = arg1 - arg2 * arg3 + end +end diff --git a/gcc/testsuite/gfortran.dg/generic_stmt_2.f90 b/gcc/testsuite/gfortran.dg/generic_stmt_2.f90 new file mode 100644 index 0000000..f698012 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/generic_stmt_2.f90 @@ -0,0 +1,87 @@ +! { dg-do compile } +! +! Test the F2018 generic statement error reporting using the module from +! generic_stmt_1.f90 +! +function cg (arg1, arg2) + complex :: cg + complex, intent(in) :: arg1, arg2 + cg = arg1 + arg2 +end + +module m1 + implicit none + + type :: t + integer :: i + end type + + public g + interface g ! Check generic statement + generic interface works + module procedure tg + end interface g + + generic, public :: g => ig ! { dg-error "repeats that already given" } + generic, private :: g => rg ! { dg-error "conflicts with that already" } + generic :: operator(.plus.) => ig, rg, gg ! { dg-error "did you mean|must be a FUNCTION" } + generic, private :: h => ig, rg + generic :: => ig, rg ! { dg-error "Malformed GENERIC statement" } + generic :: wron ng => ig, rg ! { dg-error "Expected .=>." } + generic :: #!& => ig, rg ! { dg-error "Malformed GENERIC statement" } + generic, private :: operator(.plusplus.) => ig + generic, private :: operator(.plusplus.) => rg ! { dg-error "repeats the access specification" } + generic, PUBLIC :: operator(.plusplus.) => tg ! { dg-error "must have the same access" } + + interface g ! Check generic statement + generic interface works + function cg (arg1, arg2) + complex :: cg + complex, intent(in) :: arg1, arg2 + end + end interface g + + generic, public :: sg => sig, srg + generic, public :: sg2 => sig, srg, rg ! Error appears at 'srg' declaration + + +contains + + function rg (arg1, arg2) + real :: rg + real, intent(in) :: arg1, arg2 + rg = arg1 + arg2 + end + function ig (arg1, arg2) + integer :: ig + integer, intent(in) :: arg1, arg2 + ig = arg1 + arg2 + end + function tg (arg1, arg2) result(res) + type(t) :: res + type(t), intent(in) :: arg1, arg2 + res%i = arg1%i + arg2%i + end + subroutine srg (arg1, arg2, arg3) ! { dg-error "procedures must be either all SUBROUTINEs" } + real :: arg3 + real, intent(in) :: arg1, arg2 + arg3 = arg1 + arg2 + end + subroutine sig (arg1, arg2, arg3) + integer :: arg3 + integer, intent(in) :: arg1, arg2 + arg3 = arg1 + arg2 + end + subroutine foo + real :: a = 1.0, b = 2.0, r + integer :: c = 3, d = 4 + generic, public :: sg => sig, srg ! { dg-error "not in a module" } + generic :: operator(+) => rg ! { dg-error "conflicts with intrinsic interface" } + r = h(a,d) ! { dg-error "There is no specific function" } + if (r /= rg(a,b)) stop 1 + if (h(c,d) /= ig(c,d)) stop 2 + generic :: wrong => ig, rg ! { dg-error "Unexpected GENERIC statement" } +! operator in foo + r = c.plus.b ! { dg-error "Unknown operator" } + if (r /= rg(a,b)) stop 3 + if ((c.plus.(2*d)) /= ig(c,2*d)) stop 4 + end +end module m1 diff --git a/gcc/testsuite/gfortran.dg/generic_stmt_3.f90 b/gcc/testsuite/gfortran.dg/generic_stmt_3.f90 new file mode 100644 index 0000000..543c63f --- /dev/null +++ b/gcc/testsuite/gfortran.dg/generic_stmt_3.f90 @@ -0,0 +1,96 @@ +! { dg-do compile } +! +! Test the F2018 generic statement error reporting of access and name conflicts. +! +! Contributed by Steven Kargl <kargls@comcast.net> +! + module foo1 + + implicit none + private + + public bah + generic :: bah => bah, bak ! { dg-error "conflicts with that" } + + public bar + generic :: bar => bah, bak ! OK - checked that 'bar' is not a procedure + + contains + integer function bah(i) + integer, intent(in) :: i + bah = i + end function bah + real function bak(x) + real, intent(in) :: x + bak = 42.5 + end function bak + end module foo1 + + module foo2 + + implicit none + private + + generic :: bah => bah, bak ! { dg-error "conflicts with that" } + public bah + + generic :: bar => bah, bak ! OK - checked that 'bar' is not a procedure + public bar + + contains + integer function bah(i) + integer, intent(in) :: i + bah = i + end function bah + real function bak(x) + real, intent(in) :: x + bak = 42.5 + end function bak + end module foo2 + + module foo3 ! { dg-error "clashes with the name of an entity" } + + implicit none + private + + integer :: bar = 10 ! { dg-error "has a type" } + generic :: bar => bah, bak ! { dg-error "has a type" } + + generic :: foo3 => bah, bak ! { dg-error "clashes with the name of an entity" } + + contains + integer function bah(i) + integer, intent(in) :: i + bah = i + end function bah + real function bak(x) + real, intent(in) :: x + bak = 42.5 + end function bak + end module foo3 + + module foo4 + implicit none + private + public bak + + generic :: bak => bar, bah + + contains + function bar(i) + real bar + integer, intent(in) :: i + bar = i + end function bar + function bah(x) + real bah + real, intent(in) :: x + bah = x + end function bah + end module foo4 + + program snooze + use foo4 + print *, bak(42) ! Public statement for 'bak' exposes the + print *, bak(43.5) ! specific procedures 'bar' and 'bah' here. + end program snooze diff --git a/gcc/testsuite/gfortran.dg/generic_stmt_4.f90 b/gcc/testsuite/gfortran.dg/generic_stmt_4.f90 new file mode 100644 index 0000000..24e814a --- /dev/null +++ b/gcc/testsuite/gfortran.dg/generic_stmt_4.f90 @@ -0,0 +1,43 @@ +! { dg-do run } +! +! Test the correct processing of public generic statements and verify that they +! behave in the same way as public interfaces. +! +! Contributed by Steven Kargl <kargls@comcast.net> +! +module foo + + implicit none + + private + public bak1, bak2 + + + generic :: bak1 => bar, bah + + ! Should be equivalent to above. + + interface bak2 + module procedure bar + module procedure bah + end interface bak2 + + + contains + function bar(i) + real bar + integer, intent(in) :: i + bar = i + end function bar + function bah(x) + real bah + real, intent(in) :: x + bah = x + end function bah +end module foo + +program snooze + use foo + if (bak1(42) /= bak2(42)) stop 1 + if (bak1(43.5) /= bak2(43.5)) stop 2 +end program snooze |