Fix std::variant test for ILP32 targets
authorJonathan Wakely <jwakely@redhat.com>
Fri, 17 May 2019 14:13:43 +0000 (15:13 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 17 May 2019 14:13:43 +0000 (15:13 +0100)
* testsuite/20_util/variant/compile.cc: Fix narrowing test for ILP32
targets. Add more cases from P0608R3.
* testsuite/20_util/variant/run.cc: Add more cases from P0608R3.

From-SVN: r271325

libstdc++-v3/ChangeLog
libstdc++-v3/testsuite/20_util/variant/compile.cc
libstdc++-v3/testsuite/20_util/variant/run.cc

index 397b8edd32782b86c4ef598fd9d4977704725e64..1ba66d80a1522d091bc72b2200eca778fc8fc079 100644 (file)
@@ -1,5 +1,9 @@
 2019-05-17  Jonathan Wakely  <jwakely@redhat.com>
 
+       * testsuite/20_util/variant/compile.cc: Fix narrowing test for ILP32
+       targets. Add more cases from P0608R3.
+       * testsuite/20_util/variant/run.cc: Add more cases from P0608R3.
+
        * include/bits/random.h (seed_seq::param): Fix non-reserved name.
        * include/experimental/type_traits (is_detected_exact)
        (is_detected_exact_v): Likewise.
index 4560f77445229682c7fe2008edec112abcf1a88b..dc3d4c2b3f142a8e0c0814514766f03017eb8e35 100644 (file)
@@ -144,7 +144,15 @@ void arbitrary_ctor()
   static_assert(noexcept(variant<int, DefaultNoexcept>(DefaultNoexcept{})));
 
   // P0608R3 disallow narrowing conversions and boolean conversions
-  static_assert(!is_constructible_v<variant<int>, long>);
+  static_assert(!is_constructible_v<variant<float>, int>);
+  static_assert(!is_constructible_v<variant<float, vector<int>>, int>);
+  static_assert(is_constructible_v<variant<float, int>, char>);
+  static_assert(!is_constructible_v<variant<float, char>, int>);
+  static_assert(is_constructible_v<variant<float, long>, int>);
+  struct big_int { big_int(int) { } };
+  static_assert(is_constructible_v<variant<float, big_int>, int>);
+
+  static_assert(!is_constructible_v<variant<int>, unsigned>);
   static_assert(!is_constructible_v<variant<bool>, int>);
   static_assert(!is_constructible_v<variant<bool>, void*>);
 }
index ac60ccbc13e83ef93a784bce9b230b257eb2d63e..045e1f23ada14dbad53663cca4d152d14486b619 100644 (file)
@@ -128,6 +128,17 @@ void arbitrary_ctor()
     VERIFY(y.index() == 1);
     VERIFY(std::get<1>(y).d == d);
   }
+
+  {
+    // P0608R3
+    variant<float, int> v1 = 'a';
+    VERIFY(std::get<1>(v1) == int('a'));
+    variant<float, long> v2 = 0;
+    VERIFY(std::get<1>(v2) == 0L);
+    struct big_int { big_int(int) { } };
+    variant<float, big_int> v3 = 0;
+    VERIFY(v3.index() == 1);
+  }
 }
 
 struct ThrowingMoveCtorThrowsCopyCtor