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

Hristo Hristov via libcxx-commits libcxx-commits at lists.llvm.org
Sat May 9 00:09:23 PDT 2026


================
@@ -291,6 +291,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;
----------------
Zingam wrote:

```suggestion
  _LIBCPP_HIDE_FROM_ABI explicit __bad_variant_access_with_msg(const char* __msg) _NOEXCEPT : __msg_(__msg) {}
  [[__nodiscard__]] const char* what() const _NOEXCEPT override;
```

The `[[__nodiscard__]]` needs a test probably???

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


More information about the libcxx-commits mailing list