https://gcc.gnu.org/g:190d9a2b384e626bcd0554e01513939af1ed5339
commit r15-6333-g190d9a2b384e626bcd0554e01513939af1ed5339 Author: Jakub Jelinek <ja...@redhat.com> Date: Wed Dec 18 11:59:24 2024 +0100 c++: Add {,un}likely attribute further test coverage [PR110345] Similarly for likely/unlikely attributes. 2024-12-18 Jakub Jelinek <ja...@redhat.com> PR c++/110345 * g++.dg/cpp0x/attr-likely1.C: New test. * g++.dg/cpp0x/attr-unlikely1.C: New test. Diff: --- gcc/testsuite/g++.dg/cpp0x/attr-likely1.C | 149 ++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/cpp0x/attr-unlikely1.C | 149 ++++++++++++++++++++++++++++ 2 files changed, 298 insertions(+) diff --git a/gcc/testsuite/g++.dg/cpp0x/attr-likely1.C b/gcc/testsuite/g++.dg/cpp0x/attr-likely1.C new file mode 100644 index 000000000000..f92542f89041 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/attr-likely1.C @@ -0,0 +1,149 @@ +// C++ 26 P2552R3 - On the ignorability of standard attributes +// { dg-do compile { target c++11 } } + +int arr[2]; +struct S { int a, b; }; +S arr2[2]; + +void +foo (int n) +{ + [[likely]]; + [[likely (1)]]; // { dg-error "'likely' attribute does not take any arguments" } + [[likely]] ++n; + [[likely]] int x1; // { dg-warning "'likely' attribute ignored" } + + auto a = [] [[likely]] () {}; // { dg-warning "ISO C\\\+\\\+ 'likely' attribute does not apply to functions; treating as '\\\[\\\[gnu::hot\\\]\\\]'" } + auto b = [] constexpr [[likely]] {}; // { dg-warning "'likely' attribute ignored" } + // { dg-error "parameter declaration before lambda declaration specifiers only optional with" "" { target c++20_down } .-1 } + // { dg-error "'constexpr' lambda only available with" "" { target c++14_down } .-2 } + auto c = [] noexcept [[likely]] {}; // { dg-warning "'likely' attribute ignored" } + // { dg-error "parameter declaration before lambda exception specification only optional with" "" { target c++20_down } .-1 } + auto d = [] () [[likely]] {}; // { dg-warning "'likely' attribute ignored" } + auto e = new int [n] [[likely]]; // { dg-warning "attributes ignored on outermost array type in new expression" } + auto e2 = new int [n] [[likely]] [42];// { dg-warning "attributes ignored on outermost array type in new expression" } + auto f = new int [n][42] [[likely]]; // { dg-warning "'likely' attribute ignored" } + [[likely]]; + [[likely]] {} + [[likely]] if (true) {} + [[likely]] while (false) {} + [[likely]] goto lab; + [[likely]] lab:; + [[likely]] try {} catch (int) {} + if ([[likely]] int x = 0) {} // { dg-warning "'likely' attribute ignored" } + switch (n) + { + [[likely]] case 1: + [[likely]] break; + [[likely]] default: + break; + } + for ([[likely]] auto a : arr) {} // { dg-warning "'likely' attribute ignored" } + for ([[likely]] auto [a, b] : arr2) {}// { dg-warning "'likely' attribute ignored" } + // { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } + [[likely]] asm (""); // { dg-warning "attributes ignored on 'asm' declaration" } + try {} catch ([[likely]] int x) {} // { dg-warning "'likely' attribute ignored" } + try {} catch ([[likely]] int) {} // { dg-warning "'likely' attribute ignored" } + try {} catch (int [[likely]] x) {} // { dg-warning "attribute ignored" } + try {} catch (int [[likely]]) {} // { dg-warning "attribute ignored" } + try {} catch (int x [[likely]]) {} // { dg-warning "'likely' attribute ignored" } +} + +[[likely]] int bar (); // { dg-warning "ISO C\\\+\\\+ 'likely' attribute does not apply to functions; treating as '\\\[\\\[gnu::hot\\\]\\\]'" } +using foobar [[likely]] = int; // { dg-warning "'likely' attribute ignored" } +[[likely]] int a; // { dg-warning "'likely' attribute ignored" } +[[likely]] auto [b, c] = arr; // { dg-warning "'likely' attribute ignored" } + // { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } +[[likely]]; // { dg-warning "attribute ignored" } +inline [[likely]] void baz () {} // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +constexpr [[likely]] int qux () { return 0; } // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +int [[likely]] d; // { dg-warning "attribute ignored" } +int const [[likely]] e = 1; // { dg-warning "attribute ignored" } +struct A {} [[likely]]; // { dg-warning "attribute ignored in declaration of 'struct A'" } +struct A [[likely]]; // { dg-warning "attribute ignored" } +struct A [[likely]] a1; // { dg-warning "attribute ignored" } +A [[likely]] a2; // { dg-warning "attribute ignored" } +enum B { B0 } [[likely]]; // { dg-warning "attribute ignored in declaration of 'enum B'" } +enum B [[likely]]; // { dg-warning "attribute ignored" } +enum B [[likely]] b1; // { dg-warning "attribute ignored" } +B [[likely]] b2; // { dg-warning "attribute ignored" } +struct [[likely]] C {}; // { dg-warning "'likely' attribute ignored" } +int f [[likely]]; // { dg-warning "'likely' attribute ignored" } +int g[2] [[likely]]; // { dg-warning "'likely' attribute ignored" } +int g2 [[likely]] [2]; // { dg-warning "'likely' attribute ignored" } +int corge () [[likely]]; // { dg-warning "'likely' attribute ignored" } +int *[[likely]] h; // { dg-warning "'likely' attribute ignored" } +int & [[likely]] i = f; // { dg-warning "'likely' attribute ignored" } +int && [[likely]] j = 0; // { dg-warning "'likely' attribute ignored" } +int S::* [[likely]] k; // { dg-warning "'likely' attribute ignored" } +auto l = sizeof (int [2] [[likely]]); // { dg-warning "'likely' attribute ignored" } +int freddy ([[likely]] int a, // { dg-warning "'likely' attribute ignored" } + [[likely]] int, // { dg-warning "'likely' attribute ignored" } + [[likely]] int c = 0, // { dg-warning "'likely' attribute ignored" } + [[likely]] int = 0); // { dg-warning "'likely' attribute ignored" } +void +corge ([[likely]] int a, // { dg-warning "'likely' attribute ignored" } + [[likely]] int, // { dg-warning "'likely' attribute ignored" } + [[likely]] int c = 0, // { dg-warning "'likely' attribute ignored" } + [[likely]] int = 0) // { dg-warning "'likely' attribute ignored" } +{ +} +[[likely]] void +garply () // { dg-warning "ISO C\\\+\\\+ 'likely' attribute does not apply to functions; treating as '\\\[\\\[gnu::hot\\\]\\\]'" } +{ +} +int grault (int [[likely]] a, // { dg-warning "attribute ignored" } + int [[likely]], // { dg-warning "attribute ignored" } + int [[likely]] c = 0, // { dg-warning "attribute ignored" } + int [[likely]] = 0); // { dg-warning "attribute ignored" } +void +waldo (int [[likely]] a, // { dg-warning "attribute ignored" } + int [[likely]], // { dg-warning "attribute ignored" } + int [[likely]] c = 0, // { dg-warning "attribute ignored" } + int [[likely]] = 0) // { dg-warning "attribute ignored" } +{ +} +int plugh (int a [[likely]], // { dg-warning "'likely' attribute ignored" } + int b [[likely]] = 0); // { dg-warning "'likely' attribute ignored" } +void +thud (int a [[likely]], // { dg-warning "'likely' attribute ignored" } + int b [[likely]] = 0) // { dg-warning "'likely' attribute ignored" } +{ +} +enum [[likely]] D { D0 }; // { dg-warning "'likely' attribute ignored" } +enum class [[likely]] E { E0 }; // { dg-warning "'likely' attribute ignored" } +enum F {}; +enum [[likely]] F; // { dg-warning "type attributes ignored after type is already defined" } +enum G { + G0 [[likely]], // { dg-warning "'likely' attribute ignored" } + G1 [[likely]] = 2 // { dg-warning "'likely' attribute ignored" } +}; +namespace [[likely]] H { using H0 = int; } // { dg-warning "'likely' attribute directive ignored" } */ +namespace [[likely]] {} // { dg-warning "'likely' attribute directive ignored" } +[[likely]] using namespace H; // { dg-warning "'likely' attribute directive ignored" } +struct [[likely]] I // { dg-warning "'likely' attribute ignored" } +{ + [[likely]]; // { dg-error "declaration does not declare anything" } + [[likely]] int i; // { dg-warning "'likely' attribute ignored" } + [[likely]] int foo (); // { dg-warning "ISO C\\\+\\\+ 'likely' attribute does not apply to functions; treating as '\\\[\\\[gnu::hot\\\]\\\]'" } + [[likely]] int bar () { return 1; } // { dg-warning "ISO C\\\+\\\+ 'likely' attribute does not apply to functions; treating as '\\\[\\\[gnu::hot\\\]\\\]'" } + [[likely]] int : 0; // { dg-warning "'likely' attribute ignored" } + [[likely]] int i2 : 5; // { dg-warning "'likely' attribute ignored" } + [[likely]] static int i3; // { dg-warning "'likely' attribute ignored" } + static int i4; +}; +[[likely]] int I::i4 = 0; // { dg-warning "'likely' attribute ignored" } +struct J : [[likely]] C {}; // { dg-warning "attributes on base specifiers are ignored" } +#if __cpp_concepts >= 201907L +template <typename T> +concept K [[likely]] = requires { true; }; // { dg-warning "'likely' attribute ignored" "" { target c++20 } } +#endif +typedef int L [[likely]]; // { dg-warning "'likely' attribute ignored" } +template <typename T> +struct M {}; +template <> +struct [[likely]] M<int> { int m; }; // { dg-warning "'likely' attribute ignored" } +typedef int N[2] [[likely]]; // { dg-warning "'likely' attribute ignored" } +typedef int O [[likely]] [2]; // { dg-warning "'likely' attribute ignored" } diff --git a/gcc/testsuite/g++.dg/cpp0x/attr-unlikely1.C b/gcc/testsuite/g++.dg/cpp0x/attr-unlikely1.C new file mode 100644 index 000000000000..1eb02cd63006 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/attr-unlikely1.C @@ -0,0 +1,149 @@ +// C++ 26 P2552R3 - On the ignorability of standard attributes +// { dg-do compile { target c++11 } } + +int arr[2]; +struct S { int a, b; }; +S arr2[2]; + +void +foo (int n) +{ + [[unlikely]]; + [[unlikely (1)]]; // { dg-error "'unlikely' attribute does not take any arguments" } + [[unlikely]] ++n; + [[unlikely]] int x1; // { dg-warning "'unlikely' attribute ignored" } + + auto a = [] [[unlikely]] () {}; // { dg-warning "ISO C\\\+\\\+ 'unlikely' attribute does not apply to functions; treating as '\\\[\\\[gnu::cold\\\]\\\]'" } + auto b = [] constexpr [[unlikely]] {}; // { dg-warning "'unlikely' attribute ignored" } + // { dg-error "parameter declaration before lambda declaration specifiers only optional with" "" { target c++20_down } .-1 } + // { dg-error "'constexpr' lambda only available with" "" { target c++14_down } .-2 } + auto c = [] noexcept [[unlikely]] {}; // { dg-warning "'unlikely' attribute ignored" } + // { dg-error "parameter declaration before lambda exception specification only optional with" "" { target c++20_down } .-1 } + auto d = [] () [[unlikely]] {}; // { dg-warning "'unlikely' attribute ignored" } + auto e = new int [n] [[unlikely]]; // { dg-warning "attributes ignored on outermost array type in new expression" } + auto e2 = new int [n] [[unlikely]] [42]; // { dg-warning "attributes ignored on outermost array type in new expression" } + auto f = new int [n][42] [[unlikely]]; // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]]; + [[unlikely]] {} + [[unlikely]] if (true) {} + [[unlikely]] while (false) {} + [[unlikely]] goto lab; + [[unlikely]] lab:; + [[unlikely]] try {} catch (int) {} + if ([[unlikely]] int x = 0) {} // { dg-warning "'unlikely' attribute ignored" } + switch (n) + { + [[unlikely]] case 1: + [[unlikely]] break; + [[unlikely]] default: + break; + } + for ([[unlikely]] auto a : arr) {} // { dg-warning "'unlikely' attribute ignored" } + for ([[unlikely]] auto [a, b] : arr2) {} // { dg-warning "'unlikely' attribute ignored" } + // { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } + [[unlikely]] asm (""); // { dg-warning "attributes ignored on 'asm' declaration" } + try {} catch ([[unlikely]] int x) {} // { dg-warning "'unlikely' attribute ignored" } + try {} catch ([[unlikely]] int) {} // { dg-warning "'unlikely' attribute ignored" } + try {} catch (int [[unlikely]] x) {} // { dg-warning "attribute ignored" } + try {} catch (int [[unlikely]]) {} // { dg-warning "attribute ignored" } + try {} catch (int x [[unlikely]]) {} // { dg-warning "'unlikely' attribute ignored" } +} + +[[unlikely]] int bar (); // { dg-warning "ISO C\\\+\\\+ 'unlikely' attribute does not apply to functions; treating as '\\\[\\\[gnu::cold\\\]\\\]'" } +using foobar [[unlikely]] = int; // { dg-warning "'unlikely' attribute ignored" } +[[unlikely]] int a; // { dg-warning "'unlikely' attribute ignored" } +[[unlikely]] auto [b, c] = arr; // { dg-warning "'unlikely' attribute ignored" } + // { dg-error "structured bindings only available with" "" { target c++14_down } .-1 } +[[unlikely]]; // { dg-warning "attribute ignored" } +inline [[unlikely]] void baz () {} // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +constexpr [[unlikely]] int qux () { return 0; } // { dg-warning "attribute ignored" } + // { dg-error "standard attributes in middle of decl-specifiers" "" { target *-*-* } .-1 } +int [[unlikely]] d; // { dg-warning "attribute ignored" } +int const [[unlikely]] e = 1; // { dg-warning "attribute ignored" } +struct A {} [[unlikely]]; // { dg-warning "attribute ignored in declaration of 'struct A'" } +struct A [[unlikely]]; // { dg-warning "attribute ignored" } +struct A [[unlikely]] a1; // { dg-warning "attribute ignored" } +A [[unlikely]] a2; // { dg-warning "attribute ignored" } +enum B { B0 } [[unlikely]]; // { dg-warning "attribute ignored in declaration of 'enum B'" } +enum B [[unlikely]]; // { dg-warning "attribute ignored" } +enum B [[unlikely]] b1; // { dg-warning "attribute ignored" } +B [[unlikely]] b2; // { dg-warning "attribute ignored" } +struct [[unlikely]] C {}; // { dg-warning "'unlikely' attribute ignored" } +int f [[unlikely]]; // { dg-warning "'unlikely' attribute ignored" } +int g[2] [[unlikely]]; // { dg-warning "'unlikely' attribute ignored" } +int g2 [[unlikely]] [2]; // { dg-warning "'unlikely' attribute ignored" } +int corge () [[unlikely]]; // { dg-warning "'unlikely' attribute ignored" } +int *[[unlikely]] h; // { dg-warning "'unlikely' attribute ignored" } +int & [[unlikely]] i = f; // { dg-warning "'unlikely' attribute ignored" } +int && [[unlikely]] j = 0; // { dg-warning "'unlikely' attribute ignored" } +int S::* [[unlikely]] k; // { dg-warning "'unlikely' attribute ignored" } +auto l = sizeof (int [2] [[unlikely]]); // { dg-warning "'unlikely' attribute ignored" } +int freddy ([[unlikely]] int a, // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] int, // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] int c = 0, // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] int = 0); // { dg-warning "'unlikely' attribute ignored" } +void +corge ([[unlikely]] int a, // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] int, // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] int c = 0, // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] int = 0) // { dg-warning "'unlikely' attribute ignored" } +{ +} +[[unlikely]] void +garply () // { dg-warning "ISO C\\\+\\\+ 'unlikely' attribute does not apply to functions; treating as '\\\[\\\[gnu::cold\\\]\\\]'" } +{ +} +int grault (int [[unlikely]] a, // { dg-warning "attribute ignored" } + int [[unlikely]], // { dg-warning "attribute ignored" } + int [[unlikely]] c = 0, // { dg-warning "attribute ignored" } + int [[unlikely]] = 0); // { dg-warning "attribute ignored" } +void +waldo (int [[unlikely]] a, // { dg-warning "attribute ignored" } + int [[unlikely]], // { dg-warning "attribute ignored" } + int [[unlikely]] c = 0, // { dg-warning "attribute ignored" } + int [[unlikely]] = 0) // { dg-warning "attribute ignored" } +{ +} +int plugh (int a [[unlikely]], // { dg-warning "'unlikely' attribute ignored" } + int b [[unlikely]] = 0); // { dg-warning "'unlikely' attribute ignored" } +void +thud (int a [[unlikely]], // { dg-warning "'unlikely' attribute ignored" } + int b [[unlikely]] = 0) // { dg-warning "'unlikely' attribute ignored" } +{ +} +enum [[unlikely]] D { D0 }; // { dg-warning "'unlikely' attribute ignored" } +enum class [[unlikely]] E { E0 }; // { dg-warning "'unlikely' attribute ignored" } +enum F {}; +enum [[unlikely]] F; // { dg-warning "type attributes ignored after type is already defined" } +enum G { + G0 [[unlikely]], // { dg-warning "'unlikely' attribute ignored" } + G1 [[unlikely]] = 2 // { dg-warning "'unlikely' attribute ignored" } +}; +namespace [[unlikely]] H { using H0 = int; } // { dg-warning "'unlikely' attribute directive ignored" } */ +namespace [[unlikely]] {} // { dg-warning "'unlikely' attribute directive ignored" } +[[unlikely]] using namespace H; // { dg-warning "'unlikely' attribute directive ignored" } +struct [[unlikely]] I // { dg-warning "'unlikely' attribute ignored" } +{ + [[unlikely]]; // { dg-error "declaration does not declare anything" } + [[unlikely]] int i; // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] int foo (); // { dg-warning "ISO C\\\+\\\+ 'unlikely' attribute does not apply to functions; treating as '\\\[\\\[gnu::cold\\\]\\\]'" } + [[unlikely]] int bar () { return 1; } // { dg-warning "ISO C\\\+\\\+ 'unlikely' attribute does not apply to functions; treating as '\\\[\\\[gnu::cold\\\]\\\]'" } + [[unlikely]] int : 0; // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] int i2 : 5; // { dg-warning "'unlikely' attribute ignored" } + [[unlikely]] static int i3; // { dg-warning "'unlikely' attribute ignored" } + static int i4; +}; +[[unlikely]] int I::i4 = 0; // { dg-warning "'unlikely' attribute ignored" } +struct J : [[unlikely]] C {}; // { dg-warning "attributes on base specifiers are ignored" } +#if __cpp_concepts >= 201907L +template <typename T> +concept K [[unlikely]] = requires { true; }; // { dg-warning "'unlikely' attribute ignored" "" { target c++20 } } +#endif +typedef int L [[unlikely]]; // { dg-warning "'unlikely' attribute ignored" } +template <typename T> +struct M {}; +template <> +struct [[unlikely]] M<int> { int m; }; // { dg-warning "'unlikely' attribute ignored" } +typedef int N[2] [[unlikely]]; // { dg-warning "'unlikely' attribute ignored" } +typedef int O [[unlikely]] [2]; // { dg-warning "'unlikely' attribute ignored" }