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 // UNSUPPORTED: libcpp-has-no-incomplete-format
11 
12 // libc++ supports basic_format_string in C++20 as an extension
13 // UNSUPPORTED: !stdlib=libc++ && c++20
14 
15 // <format>
16 
17 // template<class charT, class... Args>
18 // class basic_format_string<charT, type_identity_t<Args>...>
19 //
20 // template<class T> consteval basic_format_string(const T& s);
21 //
22 // This constructor does the compile-time format string validation for the
23 // std::format* functions.
24 
25 #include <format>
26 
27 #include <string_view>
28 
29 #include "test_macros.h"
30 
run()31 void run() {
32   (void)std::basic_format_string<char>{"foo"};
33   (void)std::basic_format_string<char>{"{}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
34   (void)std::basic_format_string<char, int>{"{0:{0}P}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
35   (void)std::basic_format_string<char, int>{"{0:{0}}"};
36   (void)std::basic_format_string<char, float>{"{0:{0}}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
37   (void)std::basic_format_string<char, int>{"{.3}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
38 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
39   (void)std::basic_format_string<wchar_t>{L"foo"};
40   (void)std::basic_format_string<wchar_t>{L"{}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
41   (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   (void)std::basic_format_string<wchar_t, int>{L"{0:{0}}"};
43   (void)std::basic_format_string<wchar_t, float>{L"{0:{0}}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
44   (void)std::basic_format_string<wchar_t, int>{L"{.3}"}; // expected-error-re {{call to consteval function{{.*}}is not a constant expression}}
45 #endif
46 }
47