[libcxx-commits] [libcxx] r359220 - [libc++][test] Fix noexcept assertions in variant's get tests

Casey Carter via libcxx-commits libcxx-commits at lists.llvm.org
Thu Apr 25 11:36:29 PDT 2019


Author: caseycarter
Date: Thu Apr 25 11:36:29 2019
New Revision: 359220

URL: http://llvm.org/viewvc/llvm-project?rev=359220&view=rev
Log:
[libc++][test] Fix noexcept assertions in variant's get tests

All constant expressions are non-potentially-throwing in C++14, but that is *not* the case in C++17. Change these tests of the `variant`-flavored overloads of `std::get` to expect the correct behavior when the compiler is not GCC or is GCC 9+.

Credit to Jonathan Wakely for providing an improved version of my initial change that validates the incorrect behavior on GCC < 9 as well as validating the correct behavior on other compilers.

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

Modified:
    libcxx/trunk/test/std/utilities/variant/variant.get/get_index.pass.cpp
    libcxx/trunk/test/std/utilities/variant/variant.get/get_type.pass.cpp
    libcxx/trunk/test/support/test_workarounds.h

Modified: libcxx/trunk/test/std/utilities/variant/variant.get/get_index.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.get/get_index.pass.cpp?rev=359220&r1=359219&r2=359220&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.get/get_index.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.get/get_index.pass.cpp Thu Apr 25 11:36:29 2019
@@ -37,8 +37,10 @@ void test_const_lvalue_get() {
   {
     using V = std::variant<int, const long>;
     constexpr V v(42);
-#ifndef __clang__ // Avoid https://bugs.llvm.org/show_bug.cgi?id=15481
+#ifdef TEST_WORKAROUND_CONSTEXPR_IMPLIES_NOEXCEPT
     ASSERT_NOEXCEPT(std::get<0>(v));
+#else
+    ASSERT_NOT_NOEXCEPT(std::get<0>(v));
 #endif
     ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
     static_assert(std::get<0>(v) == 42, "");
@@ -53,8 +55,10 @@ void test_const_lvalue_get() {
   {
     using V = std::variant<int, const long>;
     constexpr V v(42l);
-#ifndef __clang__ // Avoid https://bugs.llvm.org/show_bug.cgi?id=15481
+#ifdef TEST_WORKAROUND_CONSTEXPR_IMPLIES_NOEXCEPT
     ASSERT_NOEXCEPT(std::get<1>(v));
+#else
+    ASSERT_NOT_NOEXCEPT(std::get<1>(v));
 #endif
     ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &);
     static_assert(std::get<1>(v) == 42, "");

Modified: libcxx/trunk/test/std/utilities/variant/variant.get/get_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/variant/variant.get/get_type.pass.cpp?rev=359220&r1=359219&r2=359220&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/variant/variant.get/get_type.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/variant/variant.get/get_type.pass.cpp Thu Apr 25 11:36:29 2019
@@ -31,24 +31,28 @@ void test_const_lvalue_get() {
   {
     using V = std::variant<int, const long>;
     constexpr V v(42);
-#ifndef __clang__ // Avoid https://bugs.llvm.org/show_bug.cgi?id=15481
+#ifdef TEST_WORKAROUND_CONSTEXPR_IMPLIES_NOEXCEPT
     ASSERT_NOEXCEPT(std::get<int>(v));
+#else
+    ASSERT_NOT_NOEXCEPT(std::get<int>(v));
 #endif
-    ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
+    ASSERT_SAME_TYPE(decltype(std::get<int>(v)), const int &);
     static_assert(std::get<int>(v) == 42, "");
   }
   {
     using V = std::variant<int, const long>;
     const V v(42);
     ASSERT_NOT_NOEXCEPT(std::get<int>(v));
-    ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
+    ASSERT_SAME_TYPE(decltype(std::get<int>(v)), const int &);
     assert(std::get<int>(v) == 42);
   }
   {
     using V = std::variant<int, const long>;
     constexpr V v(42l);
-#ifndef __clang__ // Avoid https://bugs.llvm.org/show_bug.cgi?id=15481
+#ifdef TEST_WORKAROUND_CONSTEXPR_IMPLIES_NOEXCEPT
     ASSERT_NOEXCEPT(std::get<const long>(v));
+#else
+    ASSERT_NOT_NOEXCEPT(std::get<const long>(v));
 #endif
     ASSERT_SAME_TYPE(decltype(std::get<const long>(v)), const long &);
     static_assert(std::get<const long>(v) == 42, "");

Modified: libcxx/trunk/test/support/test_workarounds.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_workarounds.h?rev=359220&r1=359219&r2=359220&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_workarounds.h (original)
+++ libcxx/trunk/test/support/test_workarounds.h Thu Apr 25 11:36:29 2019
@@ -23,4 +23,10 @@
 # endif
 #endif
 
+#if defined(TEST_COMPILER_GCC)
+# if __GNUC__ < 9
+#  define TEST_WORKAROUND_CONSTEXPR_IMPLIES_NOEXCEPT // GCC PR 87603
+# endif
+#endif
+
 #endif // SUPPORT_TEST_WORKAROUNDS_H




More information about the libcxx-commits mailing list