Merge pull request #67707 from allevato/no-u8-prefixes

This commit is contained in:
Tony Allevato
2023-08-05 21:24:05 -04:00
committed by GitHub
5 changed files with 43 additions and 15 deletions

View File

@@ -13,6 +13,8 @@
#ifndef SWIFT_BASIC_COMPILER_H
#define SWIFT_BASIC_COMPILER_H
#include <stddef.h>
#if defined(_MSC_VER) && !defined(__clang__)
#define SWIFT_COMPILER_IS_MSVC 1
#else
@@ -190,4 +192,21 @@
#define ENUM_EXTENSIBILITY_ATTR(arg)
#endif
// The 'u8' string literal prefix creates `char` types on C++14/17 but
// `char8_t` types on C++20. To support compiling in both modes
// simultaneously, wrap Unicode literals in `SWIFT_UTF8("...")` to ensure
// that they are interpreted by the compiler as UTF-8 but always return
// `char` types.
#if defined(__cplusplus)
#if defined(__cpp_char8_t)
inline constexpr char operator""_swift_u8(char8_t c) { return c; }
inline const char *operator""_swift_u8(const char8_t *p, std::size_t) {
return reinterpret_cast<const char *>(p);
}
#define SWIFT_UTF8(literal) u8##literal##_swift_u8
#else // !defined(__cpp_char8_t)
#define SWIFT_UTF8(literal) u8##literal
#endif // defined(__cpp_char8_t)
#endif // defined(__cplusplus)
#endif // SWIFT_BASIC_COMPILER_H