From 4f0aa5b051c0d3e81478bcb495e4e072b2d9827d Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 17 Sep 2020 15:31:50 -0400 Subject: [PATCH] c++: Add tests for fixed PRs. Bugzilla inspection turned up a bunch of old(er) PRs that have been fixed. Let's include them not to regress in the future. gcc/testsuite/ChangeLog: PR c++/87530 PR c++/58156 PR c++/68828 PR c++/86002 PR c++/91525 PR c++/96223 PR c++/87032 PR c++/35098 * g++.dg/cpp0x/move-return4.C: New test. * g++.dg/cpp0x/vt-58156.C: New test. * g++.dg/cpp2a/concepts-pr68828.C: New test. * g++.dg/cpp2a/concepts-pr86002.C: New test. * g++.dg/cpp2a/concepts-pr91525.C: New test. * g++.dg/cpp2a/constexpr-indeterminate1.C: New test. * g++.dg/cpp2a/desig17.C: New test. * g++.dg/ext/attrib62.C: New test. --- gcc/testsuite/g++.dg/cpp0x/move-return4.C | 17 +++++++ gcc/testsuite/g++.dg/cpp0x/vt-58156.C | 13 ++++++ gcc/testsuite/g++.dg/cpp2a/concepts-pr68828.C | 35 ++++++++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-pr86002.C | 19 ++++++++ gcc/testsuite/g++.dg/cpp2a/concepts-pr91525.C | 17 +++++++ .../g++.dg/cpp2a/constexpr-indeterminate1.C | 46 +++++++++++++++++++ gcc/testsuite/g++.dg/cpp2a/desig17.C | 19 ++++++++ gcc/testsuite/g++.dg/ext/attrib62.C | 7 +++ 8 files changed, 173 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/move-return4.C create mode 100644 gcc/testsuite/g++.dg/cpp0x/vt-58156.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr68828.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr86002.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-pr91525.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-indeterminate1.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/desig17.C create mode 100644 gcc/testsuite/g++.dg/ext/attrib62.C diff --git a/gcc/testsuite/g++.dg/cpp0x/move-return4.C b/gcc/testsuite/g++.dg/cpp0x/move-return4.C new file mode 100644 index 00000000000..3fc58089319 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/move-return4.C @@ -0,0 +1,17 @@ +// PR c++/87530 +// { dg-do compile { target c++11 } } + +struct Base { }; + +template +struct A : Base +{ + A(); + A(Base&&); +}; + +A foo() +{ + A v; + return v; // { dg-error "cannot bind rvalue reference" "" { target c++17_down } } +} diff --git a/gcc/testsuite/g++.dg/cpp0x/vt-58156.C b/gcc/testsuite/g++.dg/cpp0x/vt-58156.C new file mode 100644 index 00000000000..f1362ee84b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/vt-58156.C @@ -0,0 +1,13 @@ +// PR c++/58156 +// { dg-do compile { target c++11 } } + +template +void Foo(U&...) {} + +template +void Foo(const U&...) {} + +void Bar() { + const int a = 0; + Foo(a); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr68828.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr68828.C new file mode 100644 index 00000000000..c9679eaa369 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr68828.C @@ -0,0 +1,35 @@ +// PR c++/68828 +// { dg-do compile { target c++20 } } + +template +struct Var +{ +}; + +struct A +{ +}; + +template +T +forward(T t) +{ + return static_cast(t); +} + +template +bool requires_types_args(V&& v, Var&, Args&&... args) +{ + return (true && ... && + requires (V&& v, Types type, Args... args) { + foo(forward(v), forward(type), + forward(args)...); + } + ); +} + +void bar() +{ + Var v; + requires_types_args(A(), v, 1, 'b'); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr86002.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr86002.C new file mode 100644 index 00000000000..daa88c5a233 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr86002.C @@ -0,0 +1,19 @@ +// PR c++/86002 +// { dg-do compile { target c++20 } } + +struct X {}; +struct Y { int i; }; + +template +int f(T t) +{ + if constexpr (requires { t.i; }) + return t.i; + else + return {}; +} + +int main() +{ + return f(X{}) + f(Y{}); +} diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr91525.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr91525.C new file mode 100644 index 00000000000..700a1802a2d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-pr91525.C @@ -0,0 +1,17 @@ +// PR c++/91525 +// { dg-do compile { target c++20 } } + +struct X { + void operator<<(long); + void operator<<(bool); +} x; +struct B { + template operator bool(); + template requires false operator bool(); +} b; + +void +fn() +{ + x << b; +} diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-indeterminate1.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-indeterminate1.C new file mode 100644 index 00000000000..6e1eb68ff68 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-indeterminate1.C @@ -0,0 +1,46 @@ +// PR c++/96223 +// { dg-do compile { target c++20 } } +// DR 1787 (if an indeterminate value is produced by an evaluation, the +// behavior is undefined except in certain cases) +// Note that P1331R2 explicitly disallows in a constant evaluation: +// - an lvalue-to-rvalue conversion that is applied to an object with +// indeterminate value ([basic.indet]). + +#include + +constexpr int +fn1 () +{ + unsigned char foo; + unsigned char u = foo; // { dg-error "not usable in a constant expression" } + return 0; +} + +constexpr int +fn2 () +{ + unsigned char foo; + int i = foo; // { dg-error "not usable in a constant expression" } + return 0; +} + +constexpr int +fn3 () +{ + unsigned char foo; + char8_t u = foo; // { dg-error "not usable in a constant expression" } + return 0; +} + +constexpr int +fn4 () +{ + std::byte foo; + std::byte b = foo; // { dg-error "not usable in a constant expression" } + return 0; +} + +constexpr int w1 = fn1 (); +constexpr int w2 = fn2 (); +constexpr int w3 = fn3 (); +constexpr int w4 = fn4 (); diff --git a/gcc/testsuite/g++.dg/cpp2a/desig17.C b/gcc/testsuite/g++.dg/cpp2a/desig17.C new file mode 100644 index 00000000000..8f55c549ca2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/desig17.C @@ -0,0 +1,19 @@ +// PR c++/87032 +// { dg-do compile { target c++20 } } + +struct f1 {int x,y;}; +struct f2 {int x,y,z,t;}; + +struct T { +const char * name; +union { + struct f1 fn1; + struct f2 fn2; +} d; +}; + +extern "C" void p(struct T); + +int main(){ +p({"%x",{.fn2={1,2,3,4}}}); +} diff --git a/gcc/testsuite/g++.dg/ext/attrib62.C b/gcc/testsuite/g++.dg/ext/attrib62.C new file mode 100644 index 00000000000..116ee829a2d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib62.C @@ -0,0 +1,7 @@ +// PR c++/35098 +// { dg-do compile } + +template struct A +{ + T a, __attribute((unused)) b; // { dg-warning "attribute ignored" } +}; -- 2.30.2