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 // constexpr basic_string_view<charT> get() const noexcept { return str; }
21
22 #include <format>
23
24 #include <cassert>
25 #include <concepts>
26 #include <string_view>
27
28 #include "test_macros.h"
29 #include "make_string.h"
30
31 #define CSTR(S) MAKE_CSTRING(CharT, S)
32 #define SV(S) MAKE_STRING_VIEW(CharT, S)
33
34 template <class CharT>
test()35 constexpr bool test() {
36 assert((std::basic_format_string<CharT>{CSTR("foo")}.get() == SV("foo")));
37 assert((std::basic_format_string<CharT, int>{CSTR("{}")}.get() == SV("{}")));
38 assert((std::basic_format_string<CharT, int, float>{CSTR("{} {:01.23L}")}.get() == SV("{} {:01.23L}")));
39
40 // Embedded NUL character
41 assert((std::basic_format_string<CharT, void*, double>{SV("{}\0{}")}.get() == SV("{}\0{}")));
42 return true;
43 }
44
main(int,char **)45 int main(int, char**) {
46 test<char>();
47 static_assert(test<char>());
48 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
49 test<wchar_t>();
50 static_assert(test<wchar_t>());
51 #endif
52 return 0;
53 }
54