1 //===----------------------------------------------------------------------===// 2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 // See https://llvm.org/LICENSE.txt for license information. 4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 // 6 //===----------------------------------------------------------------------===// 7 8 // UNSUPPORTED: c++03, c++11, c++14, c++17 9 // UNSUPPORTED: no-localization 10 // UNSUPPORTED: libcpp-has-no-incomplete-format 11 // TODO FMT Evaluate gcc-11 status 12 // UNSUPPORTED: gcc-11 13 // TODO FMT Investigate AppleClang ICE 14 // UNSUPPORTED: apple-clang-13 15 16 // <format> 17 18 // template<class... Args> 19 // string format(const locale& loc, format-string<Args...> fmt, const Args&... args); 20 // template<class... Args> 21 // wstring format(const locale& loc, wformat-string<Args...> fmt, const Args&... args); 22 23 #include <format> 24 #include <cassert> 25 #include <iostream> 26 #include <vector> 27 28 #include "test_macros.h" 29 #include "format_tests.h" 30 #include "string_literal.h" 31 32 auto test = []<string_literal fmt, class CharT, class... Args>(std::basic_string_view<CharT> expected, 33 const Args&... args) constexpr { 34 std::basic_string<CharT> out = std::format(std::locale(), fmt.template sv<CharT>(), args...); 35 if constexpr (std::same_as<CharT, char>) 36 if (out != expected) 37 std::cerr << "\nFormat string " << fmt.template sv<char>() << "\nExpected output " << expected 38 << "\nActual output " << out << '\n'; 39 assert(out == expected); 40 }; 41 42 auto test_exception = []<class CharT, class... Args>(std::string_view, std::basic_string_view<CharT>, const Args&...) { 43 // After P2216 most exceptions thrown by std::format become ill-formed. 44 // Therefore this tests does nothing. 45 // A basic ill-formed test is done in format.locale.verify.cpp 46 // The exceptions are tested by other functions that don't use the basic-format-string as fmt argument. 47 }; 48 49 int main(int, char**) { 50 format_tests<char>(test, test_exception); 51 52 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 53 format_tests_char_to_wchar_t(test); 54 format_tests<wchar_t>(test, test_exception); 55 #endif 56 57 return 0; 58 } 59