brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 23dd9fe Raw
38 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++1710 11// XFAIL: availability-fp_to_chars-missing12 13// The sample code is based on the bug report14// https://llvm.org/PR8159015//16// Tests whether this formatter does not fail to compile due to nested concept17// evaluation.18 19#include <format>20#include <variant>21 22struct X : std::variant<X*> {23  X* p = nullptr;24  constexpr const std::variant<X*>& decay() const noexcept { return *this; }25};26 27template <>28struct 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 37void bug_81590() { (void)std::format("{}", X{}); }38