c++: Add tests for fixed PRs.
authorMarek Polacek <polacek@redhat.com>
Thu, 17 Sep 2020 19:31:50 +0000 (15:31 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 17 Sep 2020 19:32:43 +0000 (15:32 -0400)
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 [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/vt-58156.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-pr68828.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-pr86002.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-pr91525.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-indeterminate1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/desig17.C [new file with mode: 0644]
gcc/testsuite/g++.dg/ext/attrib62.C [new file with mode: 0644]

diff --git a/gcc/testsuite/g++.dg/cpp0x/move-return4.C b/gcc/testsuite/g++.dg/cpp0x/move-return4.C
new file mode 100644 (file)
index 0000000..3fc5808
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/87530
+// { dg-do compile { target c++11 } }
+
+struct Base { };
+
+template<typename T>
+struct A : Base
+{
+    A();
+    A(Base&&);
+};
+
+A<int> foo()
+{
+    A<double> 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 (file)
index 0000000..f1362ee
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/58156
+// { dg-do compile { target c++11 } }
+
+template <class T, class... U>
+void Foo(U&...) {}
+
+template <class T, class... U>
+void Foo(const U&...) {}
+
+void Bar() {
+  const int a = 0;
+  Foo<int>(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 (file)
index 0000000..c9679ea
--- /dev/null
@@ -0,0 +1,35 @@
+// PR c++/68828
+// { dg-do compile { target c++20 } }
+
+template <typename... Types>
+struct Var
+{
+};
+
+struct A
+{
+};
+
+template <typename T>
+T
+forward(T t)
+{
+  return static_cast<T>(t);
+}
+
+template <typename V, typename... Types, typename... Args>
+bool requires_types_args(V&& v, Var<Types...>&, Args&&... args)
+{
+  return (true && ... &&
+    requires (V&& v, Types type, Args... args) {
+      foo(forward<V>(v), forward<Types>(type), 
+        forward<Args>(args)...);
+    }
+  );
+}
+
+void bar()
+{
+  Var<int, char> 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 (file)
index 0000000..daa88c5
--- /dev/null
@@ -0,0 +1,19 @@
+// PR c++/86002
+// { dg-do compile { target c++20 } }
+
+struct X {};
+struct Y { int i; };
+
+template <typename T>
+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 (file)
index 0000000..700a180
--- /dev/null
@@ -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 <bool = true> operator bool();
+  template <bool = true> 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 (file)
index 0000000..6e1eb68
--- /dev/null
@@ -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 <cstddef>
+
+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 (file)
index 0000000..8f55c54
--- /dev/null
@@ -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 (file)
index 0000000..116ee82
--- /dev/null
@@ -0,0 +1,7 @@
+// PR c++/35098
+// { dg-do compile }
+
+template<typename T> struct A
+{
+  T a, __attribute((unused)) b; // { dg-warning "attribute ignored" }
+};