diff --git a/libcxx/test/support/test_format_string.h b/libcxx/test/support/test_format_string.h new file mode 100644 --- /dev/null +++ b/libcxx/test/support/test_format_string.h @@ -0,0 +1,42 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef SUPPORT_TEST_FORMAT_STRING_HPP +#define SUPPORT_TEST_FORMAT_STRING_HPP + +#include +#include + +#include "test_macros.h" + +#if TEST_STD_VER < 20 +# error "The format header requires at least C++20" +#endif + +// Wrapper for basic_format_string. +// +// This layer of indirection is used since it's not possible to use +// std::basic_format_string in the test function directly. +// +// In C++20 the basic-format-string was an exposition only type. In C++23 is +// has been replaced with basic_format_string. Both libc++ and MSVC STL offer +// it as an extension in C++20. +#if TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined(_MSVC_STL_VERSION) +template +using test_format_string = + std::conditional_t, std::format_string, std::wformat_string>; + +#else // TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined( _MSVC_STL_VERSION) + +# error +"Please create a vendor specific version of the test typedef and file a review at https://reviews.llvm.org/" + +#endif // TEST_STD_VER > 20 || defined(_LIBCPP_VERSION) || defined( _MSVC_STL_VERSION) + +#endif // SUPPORT_TEST_FORMAT_STRING_HPP