[TySan] Don't report globals with incomplete types. (#121922)
[llvm-project.git] / libcxx / test / support / string_literal.h
blob0226044ce48c935547a002a5787ea67fe6efb3b4
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 //===----------------------------------------------------------------------===//
9 #ifndef SUPPORT_TEST_STRING_LITERAL_H
10 #define SUPPORT_TEST_STRING_LITERAL_H
12 #include "test_macros.h"
14 #include <algorithm>
15 #include <concepts>
16 #include <string_view>
18 #if TEST_STD_VER > 17
20 /// Helper class to "transfer" a string literal
21 ///
22 /// The MAKE_STRING helper macros turn a string literal into a const char*.
23 /// This is an issue when testing std::format; its format-string needs a string
24 /// literal for compile-time validation. This class does the job.
25 ///
26 /// \note The class assumes a wchar_t can be initialized from a char.
27 /// \note All members are public to avoid compilation errors.
28 template <std::size_t N>
29 struct string_literal {
30 consteval /*implicit*/ string_literal(const char (&str)[N + 1]) {
31 std::copy_n(str, N + 1, data_);
32 # ifndef TEST_HAS_NO_WIDE_CHARACTERS
33 std::copy_n(str, N + 1, wdata_);
34 # endif
37 template <class CharT>
38 consteval std::basic_string_view<CharT> sv() const {
39 if constexpr (std::same_as<CharT, char>)
40 return std::basic_string_view{data_};
41 # ifndef TEST_HAS_NO_WIDE_CHARACTERS
42 else
43 return std::basic_string_view{wdata_};
44 # endif
47 char data_[N + 1];
48 # ifndef TEST_HAS_NO_WIDE_CHARACTERS
49 wchar_t wdata_[N + 1];
50 # endif
53 template <std::size_t N>
54 string_literal(const char (&str)[N]) -> string_literal<N - 1>;
56 #endif // TEST_STD_VER > 17
58 #endif // SUPPORT_TEST_STRING_LITERAL_H