diff --git a/stl/inc/any b/stl/inc/any index ff810e276..76f3746bb 100644 --- a/stl/inc/any +++ b/stl/inc/any @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX17 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++17 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv #include #include diff --git a/stl/inc/barrier b/stl/inc/barrier index 37cf1c411..ee2f8d82f 100644 --- a/stl/inc/barrier +++ b/stl/inc/barrier @@ -14,7 +14,7 @@ #endif // _M_CEE_PURE #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #include diff --git a/stl/inc/bit b/stl/inc/bit index bacde1abf..391c0cdcd 100644 --- a/stl/inc/bit +++ b/stl/inc/bit @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #include diff --git a/stl/inc/charconv b/stl/inc/charconv index ab0d54a62..75021352e 100644 --- a/stl/inc/charconv +++ b/stl/inc/charconv @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX17 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++17 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv #include #include diff --git a/stl/inc/compare b/stl/inc/compare index e46bfd0bd..96aa6d382 100644 --- a/stl/inc/compare +++ b/stl/inc/compare @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #ifdef __cpp_lib_concepts #include diff --git a/stl/inc/concepts b/stl/inc/concepts index cd8ceabff..0604da200 100644 --- a/stl/inc/concepts +++ b/stl/inc/concepts @@ -10,8 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #ifndef __cpp_lib_concepts -#pragma message( \ - _WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 concepts support.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 concepts support."); #else // ^^^ !defined(__cpp_lib_concepts) / defined(__cpp_lib_concepts) vvv #include #include diff --git a/stl/inc/coroutine b/stl/inc/coroutine index 6bd8828cf..d884eba9c 100644 --- a/stl/inc/coroutine +++ b/stl/inc/coroutine @@ -10,17 +10,12 @@ #if _STL_COMPILER_PREPROCESSOR #ifdef _RESUMABLE_FUNCTIONS_SUPPORTED -#define _STL4039_COROUTINE \ - "The contents of are not available with /await. " \ - "Remove /await or use /await:strict for standard coroutines. " \ - "Use for legacy /await support." -#pragma message(_WARNING_MESSAGE("STL4039", _STL4039_COROUTINE)) -#undef _STL4039_COROUTINE // TRANSITION, DevCom-1479701 +_EMIT_STL_WARNING(STL4039, "The contents of are not available with /await. " + "Remove /await or use /await:strict for standard coroutines. " + "Use for legacy /await support."); #else // ^^^ /await ^^^ / vvv no /await vvv #ifndef __cpp_lib_coroutine -#define _STL4038_COROUTINE "The contents of are available only with C++20 or later or /await:strict." -#pragma message(_WARNING_MESSAGE("STL4038", _STL4038_COROUTINE)) -#undef _STL4038_COROUTINE // TRANSITION, DevCom-1479701 +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later or /await:strict."); #else // ^^^ is not available / is available vvv #ifndef _ALLOW_COROUTINE_ABI_MISMATCH #pragma detect_mismatch("_COROUTINE_ABI", "2") diff --git a/stl/inc/execution b/stl/inc/execution index a934df435..6314feb4c 100644 --- a/stl/inc/execution +++ b/stl/inc/execution @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX17 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++17 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv #include #include diff --git a/stl/inc/expected b/stl/inc/expected index 8ee683217..3342db7bb 100644 --- a/stl/inc/expected +++ b/stl/inc/expected @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #ifndef __cpp_lib_expected -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++23 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++23 or later."); #else // ^^^ !__cpp_lib_expected / __cpp_lib_expected vvv #include #include diff --git a/stl/inc/filesystem b/stl/inc/filesystem index 0130975f0..34fbee722 100644 --- a/stl/inc/filesystem +++ b/stl/inc/filesystem @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX17 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++17 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv #include #include diff --git a/stl/inc/format b/stl/inc/format index 44eea00d6..50ca187f1 100644 --- a/stl/inc/format +++ b/stl/inc/format @@ -40,7 +40,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #ifndef __cpp_lib_format -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !defined(__cpp_lib_format) / defined(__cpp_lib_format) vvv #include <__msvc_format_ucd_tables.hpp> diff --git a/stl/inc/latch b/stl/inc/latch index 20554a869..91d32b791 100644 --- a/stl/inc/latch +++ b/stl/inc/latch @@ -14,7 +14,7 @@ #endif // _M_CEE_PURE #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #include diff --git a/stl/inc/memory_resource b/stl/inc/memory_resource index 3b7f6828d..743809c9b 100644 --- a/stl/inc/memory_resource +++ b/stl/inc/memory_resource @@ -10,8 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX17 -#pragma message( \ - _WARNING_MESSAGE("STL4038", "The contents of are available only with C++17 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv #include #include diff --git a/stl/inc/numbers b/stl/inc/numbers index c302adc42..884c349a4 100644 --- a/stl/inc/numbers +++ b/stl/inc/numbers @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #ifdef __cpp_lib_concepts #include diff --git a/stl/inc/optional b/stl/inc/optional index f4a0118c0..f70a6ff63 100644 --- a/stl/inc/optional +++ b/stl/inc/optional @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX17 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++17 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv #if _HAS_CXX20 #include diff --git a/stl/inc/ranges b/stl/inc/ranges index eda6d3e0b..eb12830cb 100644 --- a/stl/inc/ranges +++ b/stl/inc/ranges @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #ifndef __cpp_lib_ranges -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !defined(__cpp_lib_ranges) / defined(__cpp_lib_ranges) vvv #include <__msvc_int128.hpp> #include diff --git a/stl/inc/semaphore b/stl/inc/semaphore index f27e340bf..78a8dd260 100644 --- a/stl/inc/semaphore +++ b/stl/inc/semaphore @@ -14,7 +14,7 @@ #endif // _M_CEE_PURE #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #include <__msvc_chrono.hpp> diff --git a/stl/inc/source_location b/stl/inc/source_location index cfafe7023..9bbea2160 100644 --- a/stl/inc/source_location +++ b/stl/inc/source_location @@ -9,8 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #ifndef __cpp_consteval -#pragma message( \ - _WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 consteval support.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 consteval support."); #else // ^^^ !defined(__cpp_consteval) / defined(__cpp_consteval) vvv #include diff --git a/stl/inc/span b/stl/inc/span index 55363d4d3..26b24fe3f 100644 --- a/stl/inc/span +++ b/stl/inc/span @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #include #include diff --git a/stl/inc/spanstream b/stl/inc/spanstream index e5f7cda6a..1f92d8bbc 100644 --- a/stl/inc/spanstream +++ b/stl/inc/spanstream @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX23 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++23 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++23 or later."); #else // ^^^ !_HAS_CXX23 / _HAS_CXX23 vvv #ifdef __cpp_lib_concepts #include diff --git a/stl/inc/stacktrace b/stl/inc/stacktrace index 452b4f089..43f765af5 100644 --- a/stl/inc/stacktrace +++ b/stl/inc/stacktrace @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX23 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++23 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++23 or later."); #else // ^^^ !_HAS_CXX23 / _HAS_CXX23 vvv #include diff --git a/stl/inc/stdatomic.h b/stl/inc/stdatomic.h index 29838b8c0..2e821f7f9 100644 --- a/stl/inc/stdatomic.h +++ b/stl/inc/stdatomic.h @@ -22,7 +22,7 @@ #endif // _M_CEE_PURE #if !_HAS_CXX23 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++23 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++23 or later."); #else // ^^^ !_HAS_CXX23 / _HAS_CXX23 vvv #include diff --git a/stl/inc/stop_token b/stl/inc/stop_token index d227ff664..39152a0ed 100644 --- a/stl/inc/stop_token +++ b/stl/inc/stop_token @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #include diff --git a/stl/inc/string_view b/stl/inc/string_view index f08037717..81f80a9a4 100644 --- a/stl/inc/string_view +++ b/stl/inc/string_view @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX17 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++17 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv #include #endif // _HAS_CXX17 diff --git a/stl/inc/syncstream b/stl/inc/syncstream index 154780a79..70c1e37dc 100644 --- a/stl/inc/syncstream +++ b/stl/inc/syncstream @@ -9,7 +9,7 @@ #include #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX20 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++20 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later."); #else // ^^^ !_HAS_CXX20 / _HAS_CXX20 vvv #include #include diff --git a/stl/inc/variant b/stl/inc/variant index 84e58a815..fe298f290 100644 --- a/stl/inc/variant +++ b/stl/inc/variant @@ -10,7 +10,7 @@ #if _STL_COMPILER_PREPROCESSOR #if !_HAS_CXX17 -#pragma message(_WARNING_MESSAGE("STL4038", "The contents of are available only with C++17 or later.")) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++17 or later."); #else // ^^^ !_HAS_CXX17 / _HAS_CXX17 vvv #include #include diff --git a/stl/inc/yvals.h b/stl/inc/yvals.h index 49fa0599c..4a61dee0b 100644 --- a/stl/inc/yvals.h +++ b/stl/inc/yvals.h @@ -233,7 +233,7 @@ _STL_DISABLE_CLANG_WARNINGS #ifdef _STATIC_CPPLIB #ifndef _DISABLE_DEPRECATE_STATIC_CPPLIB #ifdef _DLL -#pragma message(_WARNING_MESSAGE("STL4000", "_STATIC_CPPLIB is deprecated and will be REMOVED.")) +_EMIT_STL_WARNING(STL4000, "_STATIC_CPPLIB is deprecated and will be REMOVED."); #endif #ifdef _M_CEE_MIXED #error _STATIC_CPPLIB is not supported while building with /clr @@ -245,7 +245,7 @@ _STL_DISABLE_CLANG_WARNINGS #endif // _STATIC_CPPLIB #if defined(_M_CEE_PURE) && !defined(_SILENCE_CLR_PURE_DEPRECATION_WARNING) -#pragma message(_WARNING_MESSAGE("STL4001", "/clr:pure is deprecated and will be REMOVED.")) +_EMIT_STL_WARNING(STL4001, "/clr:pure is deprecated and will be REMOVED."); #endif #ifndef _MRTIMP2_PURE diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 789c661ab..dfe6cdfa9 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -19,8 +19,14 @@ #if _STL_COMPILER_PREPROCESSOR +// This does not use `_EMIT_STL_ERROR`, as it needs to be checked before we include anything else. +// However, `_EMIT_STL_ERROR` has a dependency on `_CRT_STRINGIZE`, defined in ``. +// Here, we employ the same technique as `_CRT_STRINGIZE` in order to avoid needing to update the line number. #ifndef __cplusplus -#error STL1003: Unexpected compiler, expected C++ compiler. +#define _STL_STRINGIZE_(S) #S +#define _STL_STRINGIZE(S) _STL_STRINGIZE_(S) +#pragma message(__FILE__ "(" _STL_STRINGIZE(__LINE__) "): STL1003: Unexpected compiler, expected C++ compiler.") +#error Error in C++ Standard Library usage #endif // __cplusplus // Implemented unconditionally: @@ -417,7 +423,25 @@ #include #include // The _HAS_CXX tags must be defined before including this. -#define _WARNING_MESSAGE(NUMBER, MESSAGE) __FILE__ "(" _CRT_STRINGIZE(__LINE__) "): warning " NUMBER ": " MESSAGE +// Note that _STL_PRAGMA is load-bearing; +// it still needs to exist even once CUDA and ICC support _Pragma. +#if defined(__CUDACC__) || defined(__INTEL_COMPILER) +#define _STL_PRAGMA(PRAGMA) __pragma(PRAGMA) +#else +#define _STL_PRAGMA(PRAGMA) _Pragma(#PRAGMA) +#endif + +#define _STL_PRAGMA_MESSAGE(MESSAGE) _STL_PRAGMA(message(MESSAGE)) +#define _EMIT_STL_MESSAGE(MESSAGE) _STL_PRAGMA_MESSAGE(__FILE__ "(" _CRT_STRINGIZE(__LINE__) "): " MESSAGE) + +// clang-format off +#define _EMIT_STL_WARNING(NUMBER, MESSAGE) \ + _EMIT_STL_MESSAGE("warning " #NUMBER ": " MESSAGE) \ + static_assert(true, "") +#define _EMIT_STL_ERROR(NUMBER, MESSAGE) \ + _EMIT_STL_MESSAGE("error " #NUMBER ": " MESSAGE) \ + static_assert(false, "Error in C++ Standard Library usage.") +// clang-format on #ifndef _STL_WARNING_LEVEL #if defined(_MSVC_WARNING_LEVEL) && _MSVC_WARNING_LEVEL >= 4 @@ -620,17 +644,17 @@ #ifndef _ALLOW_COMPILER_AND_STL_VERSION_MISMATCH #if defined(__CUDACC__) && defined(__CUDACC_VER_MAJOR__) #if __CUDACC_VER_MAJOR__ < 11 || (__CUDACC_VER_MAJOR__ == 11 && __CUDACC_VER_MINOR__ < 6) -#error STL1002: Unexpected compiler version, expected CUDA 11.6 or newer. +_EMIT_STL_ERROR(STL1002, "Unexpected compiler version, expected CUDA 11.6 or newer."); #endif // ^^^ old CUDA ^^^ #elif defined(__EDG__) // not attempting to detect __EDG_VERSION__ being less than expected #elif defined(__clang__) #if __clang_major__ < 14 -#error STL1000: Unexpected compiler version, expected Clang 14.0.0 or newer. +_EMIT_STL_ERROR(STL1000, "Unexpected compiler version, expected Clang 14.0.0 or newer."); #endif // ^^^ old Clang ^^^ #elif defined(_MSC_VER) #if _MSC_VER < 1933 // Coarse-grained, not inspecting _MSC_FULL_VER -#error STL1001: Unexpected compiler version, expected MSVC 19.33 or newer. +_EMIT_STL_ERROR(STL1001, "Unexpected compiler version, expected MSVC 19.33 or newer."); #endif // ^^^ old MSVC ^^^ #else // vvv other compilers vvv // not attempting to detect other compilers @@ -687,7 +711,7 @@ #endif // _HAS_UNEXPECTED #if _HAS_UNEXPECTED && _HAS_CXX23 -#error STL1004: C++98 unexpected() is incompatible with C++23 unexpected. +_EMIT_STL_ERROR(STL1004, "C++98 unexpected() is incompatible with C++23 unexpected."); #endif // _HAS_UNEXPECTED && _HAS_CXX23 // P0004R1 Removing Deprecated Iostreams Aliases