| 1 | // { dg-do compile { target c++20 } } |
| 2 | |
| 3 | // P2905R2 Runtime format strings |
| 4 | |
| 5 | #include <format> |
| 6 | |
| 7 | std::string rval() { return "path/etic/experience"; } |
| 8 | |
| 9 | void test_rval() |
| 10 | { |
| 11 | (void)std::make_format_args(rval()); // { dg-error "cannot bind non-const lvalue reference" } |
| 12 | } |
| 13 | |
| 14 | void test_missing_specialization() |
| 15 | { |
| 16 | struct X { }; |
| 17 | X x; |
| 18 | (void)std::make_format_args(x); // { dg-error "here" } |
| 19 | // { dg-error "std::formatter must be specialized" "" { target *-*-* } 0 } |
| 20 | } |
| 21 | |
| 22 | struct Y { }; |
| 23 | template<> class std::formatter<Y> { |
| 24 | public: |
| 25 | constexpr typename format_parse_context::iterator |
| 26 | parse(format_parse_context& c) |
| 27 | { return c.begin(); } |
| 28 | |
| 29 | template<class C> |
| 30 | typename C::iterator format(Y&, C&) const; |
| 31 | }; |
| 32 | |
| 33 | void test(std::formatter<Y>& f, std::format_parse_context& pc) { |
| 34 | f.parse(pc); |
| 35 | } |
| 36 | |
| 37 | void test_const_arg() |
| 38 | { |
| 39 | const Y y; |
| 40 | (void)std::make_format_args(y); // { dg-error "here" } |
| 41 | // { dg-error "format arg must be non-const" "" { target *-*-* } 0 } |
| 42 | } |
| 43 | |
| 44 | // { dg-prune-output "no matching function for call to .*::basic_format_arg<" } |