[PATCH] D27436: [libcxx] [test] std::get<0>([std::variant constant expression]) *is* noexcept

Casey Carter via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 5 18:34:08 PST 2016


CaseyCarter updated this revision to Diff 80365.
CaseyCarter added a comment.

Address review comments:

- Annotate the clang bug which the conditional compilation is avoiding.
- Assure the expression in question is not noexcept when not a constant expression.
- Cover get_type


https://reviews.llvm.org/D27436

Files:
  test/std/utilities/variant/variant.get/get_index.pass.cpp
  test/std/utilities/variant/variant.get/get_type.pass.cpp


Index: test/std/utilities/variant/variant.get/get_type.pass.cpp
===================================================================
--- test/std/utilities/variant/variant.get/get_type.pass.cpp
+++ test/std/utilities/variant/variant.get/get_type.pass.cpp
@@ -30,16 +30,35 @@
   {
     using V = std::variant<int, const long>;
     constexpr V v(42);
-    ASSERT_NOT_NOEXCEPT(std::get<int>(v));
+#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481
+    ASSERT_NOEXCEPT(std::get<int>(v));
+#endif
     ASSERT_SAME_TYPE(decltype(std::get<0>(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(std::get<int>(v) == 42);
+  }
+  {
+    using V = std::variant<int, const long>;
     constexpr V v(42l);
+#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481
+    ASSERT_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, "");
   }
+  {
+    using V = std::variant<int, const long>;
+    const V v(42l);
+    ASSERT_NOT_NOEXCEPT(std::get<const long>(v));
+    ASSERT_SAME_TYPE(decltype(std::get<const long>(v)), const long &);
+    assert(std::get<const long>(v) == 42);
+  }
 // FIXME: Remove these once reference support is reinstated
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {
Index: test/std/utilities/variant/variant.get/get_index.pass.cpp
===================================================================
--- test/std/utilities/variant/variant.get/get_index.pass.cpp
+++ test/std/utilities/variant/variant.get/get_index.pass.cpp
@@ -36,16 +36,35 @@
   {
     using V = std::variant<int, const long>;
     constexpr V v(42);
-    ASSERT_NOT_NOEXCEPT(std::get<0>(v));
+#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481
+    ASSERT_NOEXCEPT(std::get<0>(v));
+#endif
     ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
     static_assert(std::get<0>(v) == 42, "");
   }
   {
     using V = std::variant<int, const long>;
+    const V v(42);
+    ASSERT_NOT_NOEXCEPT(std::get<0>(v));
+    ASSERT_SAME_TYPE(decltype(std::get<0>(v)), const int &);
+    assert(std::get<0>(v) == 42);
+  }
+  {
+    using V = std::variant<int, const long>;
     constexpr V v(42l);
+#ifndef __clang__ // Avoid https://llvm.org/bugs/show_bug.cgi?id=15481
+    ASSERT_NOEXCEPT(std::get<1>(v));
+#endif
     ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &);
     static_assert(std::get<1>(v) == 42, "");
   }
+  {
+    using V = std::variant<int, const long>;
+    const V v(42l);
+    ASSERT_NOT_NOEXCEPT(std::get<1>(v));
+    ASSERT_SAME_TYPE(decltype(std::get<1>(v)), const long &);
+    assert(std::get<1>(v) == 42);
+  }
 // FIXME: Remove these once reference support is reinstated
 #if !defined(TEST_VARIANT_HAS_NO_REFERENCES)
   {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27436.80365.patch
Type: text/x-patch
Size: 3015 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161206/cfe815cf/attachment.bin>


More information about the cfe-commits mailing list