[Lldb-commits] [lldb] [lldb][test] Fix libstdc++ std::variant formatter for empty variant (PR #147283)

Michael Buch via lldb-commits lldb-commits at lists.llvm.org
Mon Jul 7 05:55:03 PDT 2025


Michael137 wrote:

> Looking up global variables is not completely ideal (can be slow and look up unrelated things). Would index_obj.GetValueAs**Signed**() == -1 work by any chance?

Actually after some more investigating it turns out the test was just flawed. A default-constructed variant has a valid index (being the first element of the variant). The only case where the index is `variant_npos` is when the variant is "valueless", which [according to cppreference](https://en.cppreference.com/w/cpp/utility/variant/valueless_by_exception.html) only happens when an exception is thrown during assignment to the variant.

I adjusted the test to test that scenario, and the formatter seems to work.

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


More information about the lldb-commits mailing list