| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11, c++14, c++17 |
| 10 | |
| 11 | // XFAIL: availability-fp_to_chars-missing |
| 12 | |
| 13 | // The sample code is based on the bug report |
| 14 | // https://github.com/llvm/llvm-project/issues/81590 |
| 15 | // |
| 16 | // Tests whether this formatter does not fail to compile due to nested concept |
| 17 | // evaluation. |
| 18 | |
| 19 | #include <format> |
| 20 | #include <variant> |
| 21 | |
| 22 | struct X : std::variant<X*> { |
| 23 | X* p = nullptr; |
| 24 | constexpr const std::variant<X*>& decay() const noexcept { return *this; } |
| 25 | }; |
| 26 | |
| 27 | template <> |
| 28 | struct std::formatter<X, char> : std::formatter<std::string, char> { |
| 29 | static constexpr auto format(const X& x, auto& ctx) { |
| 30 | if (!x.p) |
| 31 | return ctx.out(); |
| 32 | auto m = [&](const X* t) { return std::format_to(ctx.out(), "{}" , *t); }; |
| 33 | return std::visit(m, x.decay()); |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | void bug_81590() { (void)std::format("{}" , X{}); } |
| 38 | |