[all-commits] [llvm/llvm-project] 16f692: [libcxx] Enrich message for std::bad_variant_acces...

Nikita Grivin via All-commits all-commits at lists.llvm.org
Tue Jun 9 14:14:13 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 16f692338cf41c29774e13f96856f040923f5d2c
      https://github.com/llvm/llvm-project/commit/16f692338cf41c29774e13f96856f040923f5d2c
  Author: Nikita Grivin <neuronspectrelin at gmail.com>
  Date:   2026-06-09 (Tue, 09 Jun 2026)

  Changed paths:
    M libcxx/docs/ReleaseNotes/23.rst
    M libcxx/include/__configuration/availability.h
    M libcxx/include/variant
    M libcxx/lib/abi/arm64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist
    M libcxx/lib/abi/i686-linux-android23.libcxxabi.v1.stable.exceptions.nonew.abilist
    M libcxx/lib/abi/powerpc-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
    M libcxx/lib/abi/powerpc64-ibm-aix.libcxxabi.v1.stable.exceptions.nonew.abilist
    M libcxx/lib/abi/x86_64-apple-darwin.libcxxabi.v1.stable.exceptions.nonew.abilist
    M libcxx/lib/abi/x86_64-linux-android23.libcxxabi.v1.stable.exceptions.nonew.abilist
    M libcxx/lib/abi/x86_64-unknown-freebsd.libcxxabi.v1.stable.exceptions.nonew.abilist
    M libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist
    M libcxx/lib/abi/x86_64-unknown-linux-gnu.libcxxabi.v1.stable.noexceptions.nonew.abilist
    M libcxx/src/variant.cpp
    A libcxx/test/libcxx/utilities/variant/variant.bad_variant_access/good_what_message.pass.cpp

  Log Message:
  -----------
  [libcxx] Enrich message for std::bad_variant_access exception (#196495)

## Summary

`std::bad_variant_access::what()` now returns a more descriptive message
identifying the failing operation (e.g. `std::get: variant is
valueless`)
instead of the generic `bad_variant_access`. Brings libc++ to parity
with
libstdc++, which has provided richer messages for years.

Discussed in:
[RFC](https://discourse.llvm.org/t/rfc-improve-bad-variant-access-what-messages/90716)

Adds an internal derived class of `bad_variant_access` carrying a `const
char*`
message, exported from the dylib with availability annotations. The base
`bad_variant_access` class is unchanged — no ABI flag required, no
layout
change to the existing type. Throw sites in `__generic_get` and
`__throw_if_valueless` instantiate the derived type with the appropriate
literal; user code catching `bad_variant_access const&` picks up the new
`what()` via virtual dispatch.

Distinguishes three failure modes:
- `std::get: wrong alternative for variant`
- `std::get: variant is valueless`
- `std::visit: variant is valueless`

## ABI
Updated
`x86_64-unknown-linux-gnu.libcxxabi.v1.stable.exceptions.nonew.abilist`
based on a local Linux build. Other platforms' ABI lists will need
updates
per CI feedback - I don't have access to those toolchains for local
verification.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list