From 98e603e2978a761cc468b25034f32ae09b8c35bd Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Fri, 22 Jul 2022 12:00:46 -0700 Subject: [PATCH 1/8] Prettify STL error output Before: ``` PS ...\stl-tests> cl /Tc .\stl-warnings.cxx Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31517 for x64 Copyright (C) Microsoft Corporation. All rights reserved. stl-warnings.cxx ...\yvals_core.h(23): fatal error C1189: #error: STL1003: Unexpected compiler, expected C++ compiler. ``` After ``` PS ...\stl-tests> cl /Tc .\stl-warnings.cxx Microsoft (R) C/C++ Optimizing Compiler Version 19.33.31517 for x64 Copyright (C) Microsoft Corporation. All rights reserved. stl-warnings.cxx ...\yvals_core.h(432): error STL1003: Unexpected compiler, expected C++ compiler. ...\yvals_core.h(432): error C2338: static_assert failed: 'Error in C++ Standard Library usage.' ``` --- stl/inc/yvals.h | 6 ++---- stl/inc/yvals_core.h | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/stl/inc/yvals.h b/stl/inc/yvals.h index 37d41b4c907..865b51a3f3d 100644 --- a/stl/inc/yvals.h +++ b/stl/inc/yvals.h @@ -230,12 +230,10 @@ _STL_DISABLE_CLANG_WARNINGS #include -#define _WARNING_MESSAGE(NUMBER, MESSAGE) __FILE__ "(" _CRT_STRINGIZE(__LINE__) "): warning " NUMBER ": " MESSAGE - #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(4000, "_STATIC_CPPLIB is deprecated and will be REMOVED."); #endif #ifdef _M_CEE_MIXED #error _STATIC_CPPLIB is not supported while building with /clr @@ -247,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(4001, "/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 b9064e29e88..fe662c04862 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -19,10 +19,6 @@ #if _STL_COMPILER_PREPROCESSOR -#ifndef __cplusplus -#error STL1003: Unexpected compiler, expected C++ compiler. -#endif // __cplusplus - // Implemented unconditionally: // N3911 void_t // N4089 Safe Conversions In unique_ptr @@ -415,6 +411,23 @@ #include #include // The _HAS_CXX tags must be defined before including this. +#define _STL_PRAGMA(PRAGMA) _Pragma(#PRAGMA) +#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 STL" #NUMBER ": " MESSAGE) \ + static_assert(1, "") +#define _EMIT_STL_ERROR(NUMBER, MESSAGE) \ + _EMIT_STL_MESSAGE("error STL" #NUMBER ": " MESSAGE) \ + static_assert(0, "Error in C++ Standard Library usage.") +// clang-format on + +#ifndef __cplusplus +_EMIT_STL_ERROR(1003, "Unexpected compiler, expected C++ compiler."); +#endif // __cplusplus + #ifndef _STL_WARNING_LEVEL #if defined(_MSVC_WARNING_LEVEL) && _MSVC_WARNING_LEVEL >= 4 #define _STL_WARNING_LEVEL 4 @@ -616,17 +629,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(1002, "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(1000, "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(1001, "Unexpected compiler version, expected MSVC 19.33 or newer."); #endif // ^^^ old MSVC ^^^ #else // vvv other compilers vvv // not attempting to detect other compilers @@ -683,7 +696,7 @@ #endif // _HAS_UNEXPECTED #if _HAS_UNEXPECTED && _HAS_CXX23 -#error STL1004: C++98 unexpected() is incompatible with C++23 unexpected. +_EMIT_STL_ERROR(1004, "C++98 unexpected() is incompatible with C++23 unexpected."); #endif // _HAS_UNEXPECTED && _HAS_CXX23 // P0004R1 Removing Deprecated Iostreams Aliases From 7b876f39a0e3de694a88bc6caf0f036b113f060c Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Fri, 22 Jul 2022 21:17:01 -0700 Subject: [PATCH 2/8] STL CR --- stl/inc/yvals.h | 4 ++-- stl/inc/yvals_core.h | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/stl/inc/yvals.h b/stl/inc/yvals.h index 865b51a3f3d..4a61dee0b7c 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 -_EMIT_STL_WARNING(4000, "_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 @@ _EMIT_STL_WARNING(4000, "_STATIC_CPPLIB is deprecated and will be REMOVED."); #endif // _STATIC_CPPLIB #if defined(_M_CEE_PURE) && !defined(_SILENCE_CLR_PURE_DEPRECATION_WARNING) -_EMIT_STL_WARNING(4001, "/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 fe662c04862..013a5a6d701 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -411,21 +411,29 @@ #include #include // The _HAS_CXX tags must be defined before including this. -#define _STL_PRAGMA(PRAGMA) _Pragma(#PRAGMA) +// 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 STL" #NUMBER ": " MESSAGE) \ + _EMIT_STL_MESSAGE("warning " #NUMBER ": " MESSAGE) \ static_assert(1, "") #define _EMIT_STL_ERROR(NUMBER, MESSAGE) \ - _EMIT_STL_MESSAGE("error STL" #NUMBER ": " MESSAGE) \ + _EMIT_STL_MESSAGE("error " #NUMBER ": " MESSAGE) \ static_assert(0, "Error in C++ Standard Library usage.") // clang-format on #ifndef __cplusplus -_EMIT_STL_ERROR(1003, "Unexpected compiler, expected C++ compiler."); +_EMIT_STL_ERROR(STL1003, "Unexpected compiler, expected C++ compiler."); +#error Error in C++ Standard Library usage #endif // __cplusplus #ifndef _STL_WARNING_LEVEL @@ -629,17 +637,17 @@ _EMIT_STL_ERROR(1003, "Unexpected compiler, expected C++ compiler."); #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) -_EMIT_STL_ERROR(1002, "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 -_EMIT_STL_ERROR(1000, "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 -_EMIT_STL_ERROR(1001, "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 @@ -696,7 +704,7 @@ _EMIT_STL_ERROR(1001, "Unexpected compiler version, expected MSVC 19.33 or newer #endif // _HAS_UNEXPECTED #if _HAS_UNEXPECTED && _HAS_CXX23 -_EMIT_STL_ERROR(1004, "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 From ebca1704d3d432b777525df0134d5d73d5ec0b44 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Mon, 25 Jul 2022 13:12:22 -0700 Subject: [PATCH 3/8] Keep the `__cplusplus` check non-dependent on anything --- stl/inc/yvals_core.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 013a5a6d701..e1b70e3b1b5 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -19,6 +19,13 @@ #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 `` +#ifndef __cplusplus +#pragma message(__FILE__ "(1): STL1003: Unexpected compiler, expected C++ compiler."); +#error Error in C++ Standard Library usage +#endif // __cplusplus + // Implemented unconditionally: // N3911 void_t // N4089 Safe Conversions In unique_ptr @@ -425,17 +432,12 @@ // clang-format off #define _EMIT_STL_WARNING(NUMBER, MESSAGE) \ _EMIT_STL_MESSAGE("warning " #NUMBER ": " MESSAGE) \ - static_assert(1, "") + static_assert(true, "") #define _EMIT_STL_ERROR(NUMBER, MESSAGE) \ _EMIT_STL_MESSAGE("error " #NUMBER ": " MESSAGE) \ - static_assert(0, "Error in C++ Standard Library usage.") + static_assert(false, "Error in C++ Standard Library usage.") // clang-format on -#ifndef __cplusplus -_EMIT_STL_ERROR(STL1003, "Unexpected compiler, expected C++ compiler."); -#error Error in C++ Standard Library usage -#endif // __cplusplus - #ifndef _STL_WARNING_LEVEL #if defined(_MSVC_WARNING_LEVEL) && _MSVC_WARNING_LEVEL >= 4 #define _STL_WARNING_LEVEL 4 From c03a0703ff9beb4bcabe968ce02da99bb9eb4d4e Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Fri, 29 Jul 2022 09:01:55 -0700 Subject: [PATCH 4/8] fix tests --- stl/inc/coroutine | 11 ++++------- stl/inc/memory_resource | 3 +-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/stl/inc/coroutine b/stl/inc/coroutine index c1ef79e6df6..56daa95f529 100644 --- a/stl/inc/coroutine +++ b/stl/inc/coroutine @@ -10,16 +10,13 @@ #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." -_EMIT_STL_WARNING("STL4039", _STL4039_COROUTINE)); +_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."); #undef _STL4039_COROUTINE // TRANSITION, DevCom-1479701 #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)) +_EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later or /await:strict."); #undef _STL4038_COROUTINE // TRANSITION, DevCom-1479701 #else // ^^^ is not available / is available vvv #ifndef _ALLOW_COROUTINE_ABI_MISMATCH diff --git a/stl/inc/memory_resource b/stl/inc/memory_resource index 3b7f6828d38..743809c9bd2 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 From 43c77f740c094cf918386cbed38e12e6d0d8a577 Mon Sep 17 00:00:00 2001 From: Nicole Mazzuca Date: Fri, 29 Jul 2022 10:41:57 -0700 Subject: [PATCH 5/8] let's print the actual line number --- stl/inc/yvals_core.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 0ba33d5df46..73c1413beee 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -20,9 +20,12 @@ #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 `` +// 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 -#pragma message(__FILE__ "(1): 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 From 51b89bb262c23d961266f65c96726bb4ce5927e5 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Jul 2022 22:21:01 -0700 Subject: [PATCH 6/8] Code review feedback: Remove unused undefs. --- stl/inc/coroutine | 2 -- 1 file changed, 2 deletions(-) diff --git a/stl/inc/coroutine b/stl/inc/coroutine index 56daa95f529..20f8ae887e2 100644 --- a/stl/inc/coroutine +++ b/stl/inc/coroutine @@ -13,11 +13,9 @@ _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."); -#undef _STL4039_COROUTINE // TRANSITION, DevCom-1479701 #else // ^^^ /await ^^^ / vvv no /await vvv #ifndef __cpp_lib_coroutine _EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later or /await:strict."); -#undef _STL4038_COROUTINE // TRANSITION, DevCom-1479701 #else // ^^^ is not available / is available vvv #ifndef _ALLOW_COROUTINE_ABI_MISMATCH #pragma detect_mismatch("_COROUTINE_ABI", "2") From 7da7e99a4dc0e2ca547ac8e6b8d882df624c513b Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Jul 2022 22:27:37 -0700 Subject: [PATCH 7/8] Code review feedback: Fix classic `__pragma`. --- stl/inc/yvals_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/yvals_core.h b/stl/inc/yvals_core.h index 73c1413beee..dfe6cdfa97b 100644 --- a/stl/inc/yvals_core.h +++ b/stl/inc/yvals_core.h @@ -426,7 +426,7 @@ // 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) +#define _STL_PRAGMA(PRAGMA) __pragma(PRAGMA) #else #define _STL_PRAGMA(PRAGMA) _Pragma(#PRAGMA) #endif From 7e0aa5064f3b9fe28b37d5b986e762c5dc6ab31a Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Fri, 29 Jul 2022 22:32:02 -0700 Subject: [PATCH 8/8] Code review feedback: Unquote STL4039. --- stl/inc/coroutine | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/coroutine b/stl/inc/coroutine index 20f8ae887e2..d884eba9c9f 100644 --- a/stl/inc/coroutine +++ b/stl/inc/coroutine @@ -10,9 +10,9 @@ #if _STL_COMPILER_PREPROCESSOR #ifdef _RESUMABLE_FUNCTIONS_SUPPORTED -_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."); +_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 _EMIT_STL_WARNING(STL4038, "The contents of are available only with C++20 or later or /await:strict.");