1*13249036SMark de Wever //===----------------------------------------------------------------------===//
2*13249036SMark de Wever //
3*13249036SMark de Wever // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*13249036SMark de Wever // See https://llvm.org/LICENSE.txt for license information.
5*13249036SMark de Wever // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*13249036SMark de Wever //
7*13249036SMark de Wever //===----------------------------------------------------------------------===//
8*13249036SMark de Wever
9*13249036SMark de Wever // UNSUPPORTED: c++03, c++11, c++14, c++17
10*13249036SMark de Wever // UNSUPPORTED: libcpp-has-no-incomplete-format
11*13249036SMark de Wever
12*13249036SMark de Wever // libc++ supports basic_format_string in C++20 as an extension
13*13249036SMark de Wever // UNSUPPORTED: !stdlib=libc++ && c++20
14*13249036SMark de Wever
15*13249036SMark de Wever // <format>
16*13249036SMark de Wever
17*13249036SMark de Wever // template<class charT, class... Args>
18*13249036SMark de Wever // class basic_format_string<charT, type_identity_t<Args>...>
19*13249036SMark de Wever //
20*13249036SMark de Wever // template<class T> consteval basic_format_string(const T& s);
21*13249036SMark de Wever //
22*13249036SMark de Wever // This constructor does the compile-time format string validation for the
23*13249036SMark de Wever // std::format* functions.
24*13249036SMark de Wever
25*13249036SMark de Wever #include <format>
26*13249036SMark de Wever
27*13249036SMark de Wever #include <string_view>
28*13249036SMark de Wever
29*13249036SMark de Wever #include "test_macros.h"
30*13249036SMark de Wever
run()31*13249036SMark de Wever void run() {
32*13249036SMark de Wever (void)std::basic_format_string<char>{"foo"};
33*13249036SMark de Wever (void)std::basic_format_string<char>{"{}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
34*13249036SMark de Wever (void)std::basic_format_string<char, int>{"{0:{0}P}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
35*13249036SMark de Wever (void)std::basic_format_string<char, int>{"{0:{0}}"};
36*13249036SMark de Wever (void)std::basic_format_string<char, float>{"{0:{0}}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
37*13249036SMark de Wever (void)std::basic_format_string<char, int>{"{.3}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
38*13249036SMark de Wever #ifndef TEST_HAS_NO_WIDE_CHARACTERS
39*13249036SMark de Wever (void)std::basic_format_string<wchar_t>{L"foo"};
40*13249036SMark de Wever (void)std::basic_format_string<wchar_t>{L"{}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
41*13249036SMark de Wever (void)std::basic_format_string<wchar_t, int>{L"{0:{0}P}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
42*13249036SMark de Wever (void)std::basic_format_string<wchar_t, int>{L"{0:{0}}"};
43*13249036SMark de Wever (void)std::basic_format_string<wchar_t, float>{L"{0:{0}}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
44*13249036SMark de Wever (void)std::basic_format_string<wchar_t, int>{L"{.3}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
45*13249036SMark de Wever #endif
46*13249036SMark de Wever }
47