[libcxx] r347568 - [libcxx] Use a type that is always an aggregate in variant's tests

Louis Dionne ldionne at apple.com
Mon Nov 26 08:14:56 PST 2018


Author: ldionne
Date: Mon Nov 26 08:14:56 2018
New Revision: 347568

URL: http://llvm.org/viewvc/llvm-project?rev=347568&view=rev
Log:
[libcxx] Use a type that is always an aggregate in variant's tests

Summary:
In PR39232, we noticed that some variant tests started failing in C++2a mode
with recent Clangs, because the rules for literal types changed in C++2a. As
a result, a temporary fix was checked in (enabling the test only in C++17).

This commit is what I believe should be the long term fix: I removed the
tests that checked constexpr default-constructibility with a weird type
from the tests for index() and valueless_by_exception(), and instead I
added tests for those using an obviously literal type in the test for the
default constructor.

Reviewers: EricWF, mclow.lists

Subscribers: christof, jkorous, dexonsmith, arphaman, libcxx-commits, rsmith

Differential Revision: https://reviews.llvm.org/D54767

Modified:
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp
    libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp?rev=347568&r1=347567&r2=347568&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.ctor/default.pass.cpp Mon Nov 26 08:14:56 2018
@@ -32,7 +32,7 @@
 #include "variant_test_helpers.hpp"
 
 struct NonDefaultConstructible {
-  NonDefaultConstructible(int) {}
+  constexpr NonDefaultConstructible(int) {}
 };
 
 struct NotNoexcept {
@@ -99,6 +99,11 @@ void test_default_ctor_basic() {
     assert(std::get<0>(v) == 0);
   }
   {
+    std::variant<int, NonDefaultConstructible> v;
+    assert(v.index() == 0);
+    assert(std::get<0>(v) == 0);
+  }
+  {
     using V = std::variant<int, long>;
     constexpr V v;
     static_assert(v.index() == 0, "");
@@ -109,6 +114,12 @@ void test_default_ctor_basic() {
     constexpr V v;
     static_assert(v.index() == 0, "");
     static_assert(std::get<0>(v) == 0, "");
+  }
+  {
+    using V = std::variant<int, NonDefaultConstructible>;
+    constexpr V v;
+    static_assert(v.index() == 0, "");
+    static_assert(std::get<0>(v) == 0, "");
   }
 }
 

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp?rev=347568&r1=347567&r2=347568&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/index.pass.cpp Mon Nov 26 08:14:56 2018
@@ -10,14 +10,6 @@
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14
 
-// The following compilers don't consider a type an aggregate type (and
-// consequently not a literal type) if it has a base class at all.
-// In C++17, an aggregate type is allowed to have a base class if it's not
-// virtual, private, nor protected (e.g. ConstexprTestTypes:::NoCtors).
-// XFAIL: gcc-5, gcc-6
-// XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8
-// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0
-
 // <variant>
 
 // template <class ...Types> class variant;
@@ -33,14 +25,18 @@
 #include "test_macros.h"
 #include "variant_test_helpers.hpp"
 
+
 int main() {
-#if TEST_STD_VER == 17
-  { // This test does not pass on C++20 or later; see https://bugs.llvm.org/show_bug.cgi?id=39232
-    using V = std::variant<int, ConstexprTestTypes::NoCtors>;
+  {
+    using V = std::variant<int, long>;
     constexpr V v;
     static_assert(v.index() == 0, "");
   }
-#endif
+  {
+    using V = std::variant<int, long>;
+    V v;
+    assert(v.index() == 0);
+  }
   {
     using V = std::variant<int, long>;
     constexpr V v(std::in_place_index<1>);

Modified: libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp?rev=347568&r1=347567&r2=347568&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.variant/variant.status/valueless_by_exception.pass.cpp Mon Nov 26 08:14:56 2018
@@ -10,14 +10,6 @@
 
 // UNSUPPORTED: c++98, c++03, c++11, c++14
 
-// The following compilers don't consider a type an aggregate type (and
-// consequently not a literal type) if it has a base class at all.
-// In C++17, an aggregate type is allowed to have a base class if it's not
-// virtual, private, nor protected (e.g. ConstexprTestTypes:::NoCtors).
-// XFAIL: gcc-5, gcc-6
-// XFAIL: clang-3.5, clang-3.6, clang-3.7, clang-3.8
-// XFAIL: apple-clang-6, apple-clang-7, apple-clang-8.0
-
 // <variant>
 
 // template <class ...Types> class variant;
@@ -33,14 +25,18 @@
 #include "test_macros.h"
 #include "variant_test_helpers.hpp"
 
+
 int main() {
-#if TEST_STD_VER == 17
-  { // This test does not pass on C++20 or later; see https://bugs.llvm.org/show_bug.cgi?id=39232
-    using V = std::variant<int, ConstexprTestTypes::NoCtors>;
+  {
+    using V = std::variant<int, long>;
     constexpr V v;
     static_assert(!v.valueless_by_exception(), "");
   }
-#endif
+  {
+    using V = std::variant<int, long>;
+    V v;
+    assert(!v.valueless_by_exception());
+  }
   {
     using V = std::variant<int, long, std::string>;
     const V v("abc");




More information about the libcxx-commits mailing list