summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite
diff options
context:
space:
mode:
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r--libstdc++-v3/testsuite/20_util/reference_from_temporary/value.cc110
-rw-r--r--libstdc++-v3/testsuite/20_util/reference_from_temporary/value2.cc28
-rw-r--r--libstdc++-v3/testsuite/20_util/reference_from_temporary/version.cc27
-rw-r--r--libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc14
4 files changed, 179 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/reference_from_temporary/value.cc b/libstdc++-v3/testsuite/20_util/reference_from_temporary/value.cc
new file mode 100644
index 00000000000..2f62e54d46d
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/reference_from_temporary/value.cc
@@ -0,0 +1,110 @@
+// Copyright (C) 2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <type_traits>
+#include <testsuite_tr1.h>
+
+#ifndef __cpp_lib_reference_from_temporary
+# error "Feature test macro for reference_from_temporary is missing in <version>"
+#elif __cpp_lib_reference_from_temporary < 202202L
+# error "Feature test macro for reference_from_temporary has wrong value in <version>"
+#endif
+
+void test01()
+{
+ using std::reference_constructs_from_temporary;
+ using std::reference_converts_from_temporary;
+ using namespace __gnu_test;
+
+ struct A { A(); };
+
+ struct B {
+ operator int();
+ explicit operator int&&();
+ };
+
+ struct C {
+ operator int();
+ explicit operator int&();
+ };
+
+ static_assert(test_property<reference_constructs_from_temporary, int, int>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, void>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, const volatile void>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, void, void>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, int>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, int&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, int&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, long>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, long&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, long&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, const int&, int>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, const int&, int&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, const int&, int&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, const int&, long>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, const int&, long&>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, const int&, long&&>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&&, int>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&&, int&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&&, int&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&&, long>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&&, long&>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&&, long&&>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, const A&, A>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, const A&, A&&>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, A&&, A>(true), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&, int[]>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, const int&, int[]>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, int&&, int[]>(false), "");
+
+ static_assert(test_property<reference_converts_from_temporary, int, int>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, void>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, const volatile void>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, void, void>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, int>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, int&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, int&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, long>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, long&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, long&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, const int&, int>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, const int&, int&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, const int&, int&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, const int&, long>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, const int&, long&>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, const int&, long&&>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, int&&, int>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, int&&, int&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&&, int&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&&, long>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, int&&, long&>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, int&&, long&&>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, const A&, A>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, const A&, A&&>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, A&&, A>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, int&, int[]>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, const int&, int[]>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&&, int[]>(false), "");
+
+ static_assert(test_property<reference_constructs_from_temporary, int&&, B>(false), "");
+ static_assert(test_property<reference_constructs_from_temporary, const int&, C>(false), "");
+ static_assert(test_property<reference_converts_from_temporary, int&&, B>(true), "");
+ static_assert(test_property<reference_converts_from_temporary, const int&, C>(true), "");
+}
diff --git a/libstdc++-v3/testsuite/20_util/reference_from_temporary/value2.cc b/libstdc++-v3/testsuite/20_util/reference_from_temporary/value2.cc
new file mode 100644
index 00000000000..65770754299
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/reference_from_temporary/value2.cc
@@ -0,0 +1,28 @@
+// Copyright (C) 2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <type_traits>
+#include <string>
+
+void test01()
+{
+ static_assert(std::reference_converts_from_temporary_v<const std::string&, const char*>);
+ static_assert(std::reference_constructs_from_temporary_v<const std::string&, const char*>);
+}
diff --git a/libstdc++-v3/testsuite/20_util/reference_from_temporary/version.cc b/libstdc++-v3/testsuite/20_util/reference_from_temporary/version.cc
new file mode 100644
index 00000000000..f56e7c0dabc
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/reference_from_temporary/version.cc
@@ -0,0 +1,27 @@
+// Copyright (C) 2022 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++23" }
+// { dg-do compile { target c++23 } }
+
+#include <version>
+
+#ifndef __cpp_lib_reference_from_temporary
+# error "Feature test macro for reference_from_temporary is missing in <version>"
+#elif __cpp_lib_reference_from_temporary < 202202L
+# error "Feature test macro for reference_from_temporary has wrong value in <version>"
+#endif
diff --git a/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc b/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
index 9b3957f7d47..2b03ad7067d 100644
--- a/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
+++ b/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
@@ -346,3 +346,17 @@ static_assert(disjunction_v<false_type, false_type,
true_type>, "");
static_assert(!disjunction_v<false_type, false_type,
false_type>, "");
+#if __cpp_lib_reference_from_temporary >= 202202L
+static_assert(std::reference_converts_from_temporary_v<int&&, int>
+ && std::reference_converts_from_temporary_v<const int&, int>
+ && !std::reference_converts_from_temporary_v<int&&, int&&>
+ && !std::reference_converts_from_temporary_v<const int&, int&&>
+ && std::reference_converts_from_temporary_v<int&&, long&&>
+ && std::reference_converts_from_temporary_v<int&&, long>, "");
+static_assert(std::reference_constructs_from_temporary_v<int&&, int>
+ && std::reference_constructs_from_temporary_v<const int&, int>
+ && !std::reference_constructs_from_temporary_v<int&&, int&&>
+ && !std::reference_constructs_from_temporary_v<const int&, int&&>
+ && std::reference_constructs_from_temporary_v<int&&, long&&>
+ && std::reference_constructs_from_temporary_v<int&&, long>, "");
+#endif