[VPlan] Perform DT expensive input DT verification earlier (NFC).
[llvm-project.git] / libcxx / test / std / utilities / format / format.functions / bug_81590.compile.pass.cpp
blobc2508fdee092e3cf2679490a801632e0d166307c
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 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // XFAIL: availability-fp_to_chars-missing
13 // The sample code is based on the bug report
14 // https://github.com/llvm/llvm-project/issues/81590
16 // Tests whether this formatter does not fail to compile due to nested concept
17 // evaluation.
19 #include <format>
20 #include <variant>
22 struct X : std::variant<X*> {
23 X* p = nullptr;
24 constexpr const std::variant<X*>& decay() const noexcept { return *this; }
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());
37 void bug_81590() { (void)std::format("{}", X{}); }