[libcxx] r288571 - Fix <variant> w/o exception support

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 2 17:58:07 PST 2016


Author: ericwf
Date: Fri Dec  2 19:58:07 2016
New Revision: 288571

URL: http://llvm.org/viewvc/llvm-project?rev=288571&view=rev
Log:
Fix <variant> w/o exception support

Modified:
    libcxx/trunk/include/variant

Modified: libcxx/trunk/include/variant
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/variant?rev=288571&r1=288570&r2=288571&view=diff
==============================================================================
--- libcxx/trunk/include/variant (original)
+++ libcxx/trunk/include/variant Fri Dec  2 19:58:07 2016
@@ -225,6 +225,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
 
 #if _LIBCPP_STD_VER > 14
 
+_LIBCPP_NORETURN
+inline _LIBCPP_INLINE_VISIBILITY
+void __throw_bad_variant_access() {
+#ifndef _LIBCPP_NO_EXCEPTIONS
+        throw bad_variant_access();
+#else
+        _VSTD::abort();
+#endif
+}
+
 template <class... _Types>
 class _LIBCPP_TYPE_VIS_ONLY variant;
 
@@ -1291,7 +1301,7 @@ inline _LIBCPP_INLINE_VISIBILITY
 static constexpr auto&& __generic_get(_Vp&& __v) {
   using __variant_detail::__access::__variant;
   if (!__holds_alternative<_Ip>(__v)) {
-    throw bad_variant_access{};
+    __throw_bad_variant_access();
   }
   return __variant::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v)).__value;
 }
@@ -1483,7 +1493,7 @@ constexpr decltype(auto) visit(_Visitor&
   bool __results[] = {__vs.valueless_by_exception()...};
   for (bool __result : __results) {
     if (__result) {
-      throw bad_variant_access{};
+      __throw_bad_variant_access();
     }
   }
   return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor),




More information about the cfe-commits mailing list