[libcxx-commits] [libcxx] [libcxx] Enrich message for std::bad_variant_access exception (PR #196495)

Nikita Grivin via libcxx-commits libcxx-commits at lists.llvm.org
Tue May 26 02:11:25 PDT 2026


================
@@ -292,6 +292,17 @@ public:
   [[__nodiscard__]] const char* what() const _NOEXCEPT override;
 };
 
+#  if _LIBCPP_AVAILABILITY_HAS_BAD_VARIANT_ACCESS_GOOD_WHAT_MESSAGE
+class _LIBCPP_EXPORTED_FROM_ABI __bad_variant_access_with_msg : public bad_variant_access {
+public:
+  _LIBCPP_HIDE_FROM_ABI explicit __bad_variant_access_with_msg(const char* __msg) _NOEXCEPT : __msg_(__msg) {}
+  [[__nodiscard__]] const char* what() const _NOEXCEPT override;
----------------
MindSpectre wrote:

The class is now always present, with an inline  `_LIBCPP_HIDE_FROM_ABI_VIRTUAL what()` when the key function isn't in the dylib, so the message works on back-deployment too.
 Dropped the availability #if/#else in the throw helper and the guard in `variant.cpp`, and renamed the macro to  `_KEY_FUNCTION` to match that convention.

https://github.com/llvm/llvm-project/pull/196495


More information about the libcxx-commits mailing list