From c575d567574bc7bc04244c8b81d341bb373a4801 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 01:49:53 +0700 Subject: [PATCH 01/36] Fix conditional `char8_t` from `format.h` and fix `-Wunused-result` of [[no_discard]] begin() when in c++17 --- test/format-test.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index 3321a552bc63..99fa2f01be39 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2491,10 +2491,19 @@ TEST(FormatTest, FmtStringInTemplate) { #endif // FMT_USE_CONSTEXPR +// C++20 feature test, since r346892 Clang considers char8_t a fundamental +// type in this mode. If this is the case __cpp_char8_t will be defined. +#ifndef __cpp_char8_t +// A UTF-8 code unit type. +#define CHAR8_T fmt::char8_t +#else +#define CHAR8_T char8_t +#endif + TEST(FormatTest, ConstructU8StringViewFromCString) { fmt::u8string_view s("ab"); EXPECT_EQ(s.size(), 2u); - const fmt::char8_t* data = s.data(); + const CHAR8_T* data = s.data(); EXPECT_EQ(data[0], 'a'); EXPECT_EQ(data[1], 'b'); } @@ -2502,7 +2511,7 @@ TEST(FormatTest, ConstructU8StringViewFromCString) { TEST(FormatTest, ConstructU8StringViewFromDataAndSize) { fmt::u8string_view s("foobar", 3); EXPECT_EQ(s.size(), 3u); - const fmt::char8_t* data = s.data(); + const CHAR8_T* data = s.data(); EXPECT_EQ(data[0], 'f'); EXPECT_EQ(data[1], 'o'); EXPECT_EQ(data[2], 'o'); @@ -2513,7 +2522,7 @@ TEST(FormatTest, U8StringViewLiteral) { using namespace fmt::literals; fmt::u8string_view s = "ab"_u; EXPECT_EQ(s.size(), 2u); - const fmt::char8_t* data = s.data(); + const CHAR8_T* data = s.data(); EXPECT_EQ(data[0], 'a'); EXPECT_EQ(data[1], 'b'); EXPECT_EQ(format("{:*^5}"_u, "🤡"_u), "**🤡**"_u); @@ -2536,6 +2545,6 @@ TEST(FormatTest, CharTraitsIsNotAmbiguous) { char_traits::char_type c; #if __cplusplus >= 201103L std::string s; - begin(s); + auto lval = begin(s); #endif } From 28588a937e6a0472899b8b816b243f5aeec1bd49 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 01:53:49 +0700 Subject: [PATCH 02/36] Suppress `-Winconsistent-dllimport` when in clang-target-msvc --- test/posix-mock-test.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/posix-mock-test.cc b/test/posix-mock-test.cc index 75660ea5d4f0..fc62627fd0e0 100644 --- a/test/posix-mock-test.cc +++ b/test/posix-mock-test.cc @@ -461,6 +461,10 @@ struct LocaleMock { # ifdef _MSC_VER # pragma warning(push) # pragma warning(disable : 4273) +# ifdef __clang__ +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Winconsistent-dllimport" +# endif _locale_t _create_locale(int category, const char* locale) { return LocaleMock::instance->newlocale(category, locale, 0); @@ -473,6 +477,9 @@ void _free_locale(_locale_t locale) { double _strtod_l(const char* nptr, char** endptr, _locale_t locale) { return LocaleMock::instance->strtod_l(nptr, endptr, locale); } +# ifdef __clang__ +# pragma clang diagnostic pop +# endif # pragma warning(pop) # endif From abb3050e39b81777a43241670d1c883f44882671 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 02:06:05 +0700 Subject: [PATCH 03/36] Suppress warning _CRT_SECURE_NO_WARNINGS in MSVC and -Wdeprecated-declarations Suppress warning _CRT_SECURE_NO_WARNINGS in MSVC and -Wdeprecated-declarations of POSIX functions in Clang target MSVC. Those functions are used by gtest. --- test/CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e3667d066111..d45fe681855e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,9 +21,16 @@ if (NOT SUPPORTS_VARIADIC_TEMPLATES) target_compile_definitions(gmock PUBLIC GTEST_LANG_CXX11=0) endif () -# Workaround a bug in implementation of variadic templates in MSVC11. if (MSVC) + # Workaround a bug in implementation of variadic templates in MSVC11. target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10) + # Automatic enable exception + target_compile_options(gmock PUBLIC /EHsc) + # Disable MSVC warning of _CRT_INSECURE_DEPRECATE functions and POSIX functions + target_compile_definitions(gmock PUBLIC _CRT_SECURE_NO_WARNINGS) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(gmock PUBLIC -Wno-deprecated-declarations) + endif () endif () # GTest doesn't detect with clang. From 63d644559255ccc29305ba5d1f245318a8175d40 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 02:14:14 +0700 Subject: [PATCH 04/36] Turn on exceptions automatically in MSVC User must manually turn on exceptions otherwise error occurs when compiling `format.cc` as below fmt-master\include\fmt/format-inl.h(891,3): error: cannot use 'try' with exceptions disabled FMT_TRY { ^ --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee0142c5ee48..46b43438da95 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,6 +161,9 @@ endif () if (FMT_PEDANTIC) target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () +if (MSVC) + target_compile_options(fmt PRIVATE /EHsc) +endif () target_compile_features(fmt INTERFACE ${FMT_REQUIRED_FEATURES}) From c8cbf57e0655f66a94eef94405cc14da86ff3418 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 12:22:32 +0700 Subject: [PATCH 05/36] Use 'using' to provide char8_t type if neccessary as Victor's suggestion --- test/format-test.cc | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index 99fa2f01be39..2874290ce405 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2494,16 +2494,14 @@ TEST(FormatTest, FmtStringInTemplate) { // C++20 feature test, since r346892 Clang considers char8_t a fundamental // type in this mode. If this is the case __cpp_char8_t will be defined. #ifndef __cpp_char8_t -// A UTF-8 code unit type. -#define CHAR8_T fmt::char8_t -#else -#define CHAR8_T char8_t +// Locally provide type char8_t defined in format.h +using fmt::char8_t #endif TEST(FormatTest, ConstructU8StringViewFromCString) { fmt::u8string_view s("ab"); EXPECT_EQ(s.size(), 2u); - const CHAR8_T* data = s.data(); + const char8_t* data = s.data(); EXPECT_EQ(data[0], 'a'); EXPECT_EQ(data[1], 'b'); } @@ -2511,7 +2509,7 @@ TEST(FormatTest, ConstructU8StringViewFromCString) { TEST(FormatTest, ConstructU8StringViewFromDataAndSize) { fmt::u8string_view s("foobar", 3); EXPECT_EQ(s.size(), 3u); - const CHAR8_T* data = s.data(); + const char8_t* data = s.data(); EXPECT_EQ(data[0], 'f'); EXPECT_EQ(data[1], 'o'); EXPECT_EQ(data[2], 'o'); @@ -2522,7 +2520,7 @@ TEST(FormatTest, U8StringViewLiteral) { using namespace fmt::literals; fmt::u8string_view s = "ab"_u; EXPECT_EQ(s.size(), 2u); - const CHAR8_T* data = s.data(); + const char8_t* data = s.data(); EXPECT_EQ(data[0], 'a'); EXPECT_EQ(data[1], 'b'); EXPECT_EQ(format("{:*^5}"_u, "🤡"_u), "**🤡**"_u); From d75c98b51573b8e15bcb6d1f2f604324f9e83658 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 12:56:02 +0700 Subject: [PATCH 06/36] Narrowing scope to clang-target-msvc for mirroring cl default /EHsc --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 46b43438da95..c392c9da8a2c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,7 +161,7 @@ endif () if (FMT_PEDANTIC) target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () -if (MSVC) +if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") # mirroring cl default target_compile_options(fmt PRIVATE /EHsc) endif () From d7b83ff48e30d19a5d450a4afceba06df98844be Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 12:59:52 +0700 Subject: [PATCH 07/36] Narrowing /EHsc to clang-target-msvc only --- test/CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d45fe681855e..eded0aecea62 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,12 +24,13 @@ endif () if (MSVC) # Workaround a bug in implementation of variadic templates in MSVC11. target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10) - # Automatic enable exception - target_compile_options(gmock PUBLIC /EHsc) - # Disable MSVC warning of _CRT_INSECURE_DEPRECATE functions and POSIX functions + # Disable MSVC warnings of _CRT_INSECURE_DEPRECATE functions. target_compile_definitions(gmock PUBLIC _CRT_SECURE_NO_WARNINGS) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + # Disable MSVC warnings of POSIX functions. target_compile_options(gmock PUBLIC -Wno-deprecated-declarations) + # Mirroring MSVC cl default + target_compile_options(gmock PUBLIC /EHsc) endif () endif () From 073571a88aebdc557f0fedf01089578e86ea363b Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 13:48:40 +0700 Subject: [PATCH 08/36] missing that semicolon! --- test/format-test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/format-test.cc b/test/format-test.cc index 2874290ce405..20ff737f6401 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2495,7 +2495,7 @@ TEST(FormatTest, FmtStringInTemplate) { // type in this mode. If this is the case __cpp_char8_t will be defined. #ifndef __cpp_char8_t // Locally provide type char8_t defined in format.h -using fmt::char8_t +using fmt::char8_t; #endif TEST(FormatTest, ConstructU8StringViewFromCString) { From eb420be65d3b4ac090d45390af72d30054c970b9 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 15:55:21 +0700 Subject: [PATCH 09/36] Receive FMT_MSVC_EH from user --- CMakeLists.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c392c9da8a2c..9971c5328924 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,8 +161,20 @@ endif () if (FMT_PEDANTIC) target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () -if (MSVC AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") # mirroring cl default - target_compile_options(fmt PRIVATE /EHsc) + +# Insert FMT_MSVC_EH if user provides. +# If not, default to /EHsc in clang target msvc. +if (MSVC) + if (FMT_MSVC_EH) + set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) + else () + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") ) + set(FMT_CUSTOM_MSVC_EH /EHsc) + else () + set(FMT_CUSTOM_MSVC_EH) + endif () + endif () + target_compile_options(fmt PRIVATE ${FMT_CUSTOM_MSVC_EH}) endif () target_compile_features(fmt INTERFACE ${FMT_REQUIRED_FEATURES}) From b17216a4525568f2781265f56a7887f37478d912 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 15:56:10 +0700 Subject: [PATCH 10/36] Receive FMT_MSVC_EH from user --- test/CMakeLists.txt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eded0aecea62..f13794efe163 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -29,9 +29,19 @@ if (MSVC) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Disable MSVC warnings of POSIX functions. target_compile_options(gmock PUBLIC -Wno-deprecated-declarations) - # Mirroring MSVC cl default - target_compile_options(gmock PUBLIC /EHsc) endif () + # Insert FMT_MSVC_EH if user provides. + # if not, default to /EHsc in clang target msvc. + if (FMT_MSVC_EH) + set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) + endif () + else () + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") ) + set(FMT_CUSTOM_MSVC_EH /EHsc) + else () + set(FMT_CUSTOM_MSVC_EH) + endif () + target_compile_options(fmt PRIVATE ${FMT_CUSTOM_MSVC_EH}) endif () # GTest doesn't detect with clang. From e7e48c33799f199802cd42a827f3bf42c89e6d73 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 16:26:33 +0700 Subject: [PATCH 11/36] Fix excessing parenthesis --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9971c5328924..544f3ca6f1d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,7 @@ if (MSVC) if (FMT_MSVC_EH) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) else () - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") ) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) From c0790969a1013ddefc2265f693b4e06e1b9a577e Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 16:27:17 +0700 Subject: [PATCH 12/36] Fix excessing parenthesis --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index f13794efe163..a066607afd83 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,7 +36,7 @@ if (MSVC) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) endif () else () - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") ) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) From 9d0de74f0d99be40873dd44d625f91f53ed486db Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 16:45:02 +0700 Subject: [PATCH 13/36] Fix AppleClang match --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 544f3ca6f1d0..325f46d06acd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -168,7 +168,8 @@ if (MSVC) if (FMT_MSVC_EH) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) else () - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if ( (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") ) set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) From 6593a07faea1b58a74ba5bd76b803fdcf49dcb90 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 16:46:09 +0700 Subject: [PATCH 14/36] Fix AppleClang match --- test/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a066607afd83..bf0617f424c9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,7 +36,8 @@ if (MSVC) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) endif () else () - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if ( (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") ) set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) From bdc49297e18a4d424f6eaaefee9215f13f1e7c32 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 17:17:15 +0700 Subject: [PATCH 15/36] Try workaround with WIN32 somehow TravisCI evaluates MSVC true --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 325f46d06acd..ff1a3daa960e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -169,7 +169,7 @@ if (MSVC) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) else () if ( (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") ) + AND WIN32 ) set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) From 28b559ec563ee4392dfe5d871b52ab2180932928 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 17:19:31 +0700 Subject: [PATCH 16/36] Try workaround with WIN32 --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bf0617f424c9..5344e1c99011 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,7 +37,7 @@ if (MSVC) endif () else () if ( (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "AppleClang") ) + AND WIN32 ) set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) From 133af4a9c29b5449d970ac7b9d64c9d69c77e62b Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 17:36:26 +0700 Subject: [PATCH 17/36] Because TravisCI evaluates MSVC true in linux and apple So workaround with replacing If (MSVC) with if (MSVC AND WIN32) --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff1a3daa960e..8849b203140a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,12 +164,11 @@ endif () # Insert FMT_MSVC_EH if user provides. # If not, default to /EHsc in clang target msvc. -if (MSVC) +if (MSVC AND WIN32) if (FMT_MSVC_EH) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) else () - if ( (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - AND WIN32 ) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) From 39a140ac9d66ae9e22c508e2e85d2fba12569e53 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 17:38:00 +0700 Subject: [PATCH 18/36] Because TravisCI evaluates MSVC true in linux and apple Workaround by replacing if (MSVC) with if (MSVC AND WIN32) --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5344e1c99011..599774a8db13 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,7 +21,7 @@ if (NOT SUPPORTS_VARIADIC_TEMPLATES) target_compile_definitions(gmock PUBLIC GTEST_LANG_CXX11=0) endif () -if (MSVC) +if (MSVC AND WIN32) # Workaround a bug in implementation of variadic templates in MSVC11. target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10) # Disable MSVC warnings of _CRT_INSECURE_DEPRECATE functions. From 032ac28c1d2c06808bce25a29a747a75a049e061 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 17:59:21 +0700 Subject: [PATCH 19/36] Bring _VARIADIC_MAX=10 out of MSVC AND WIN32 context --- test/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 599774a8db13..703a310ea629 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,9 +21,12 @@ if (NOT SUPPORTS_VARIADIC_TEMPLATES) target_compile_definitions(gmock PUBLIC GTEST_LANG_CXX11=0) endif () -if (MSVC AND WIN32) - # Workaround a bug in implementation of variadic templates in MSVC11. +# Workaround a bug in implementation of variadic templates in MSVC11. +if (MSVC) target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10) +endif () + +if (MSVC AND WIN32) # Disable MSVC warnings of _CRT_INSECURE_DEPRECATE functions. target_compile_definitions(gmock PUBLIC _CRT_SECURE_NO_WARNINGS) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") From 8d8f7b1fae8162432ba7a2c7d91c2c2d6a31ba2f Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 18:04:55 +0700 Subject: [PATCH 20/36] gmock PUBLIC --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 703a310ea629..d36e223fade1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -45,7 +45,7 @@ if (MSVC AND WIN32) else () set(FMT_CUSTOM_MSVC_EH) endif () - target_compile_options(fmt PRIVATE ${FMT_CUSTOM_MSVC_EH}) + target_compile_options(gmock PUBLIC ${FMT_CUSTOM_MSVC_EH}) endif () # GTest doesn't detect with clang. From 473ccd01d7d41a5f4c08dcb6f6124e780fbf8b5f Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 18:06:10 +0700 Subject: [PATCH 21/36] Update CMakeLists.txt --- test/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d36e223fade1..bc182c871d5e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -39,8 +39,7 @@ if (MSVC AND WIN32) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) endif () else () - if ( (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - AND WIN32 ) + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) From ade161dbdc8a6980f16b8df95e8b7136c99fe082 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 18:12:20 +0700 Subject: [PATCH 22/36] Update CMakeLists.txt --- test/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bc182c871d5e..10a3b88363c9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,7 +37,6 @@ if (MSVC AND WIN32) # if not, default to /EHsc in clang target msvc. if (FMT_MSVC_EH) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) - endif () else () if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(FMT_CUSTOM_MSVC_EH /EHsc) From ff44d1a35862703ff42e5c8fd9913b21163ad849 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 18:22:49 +0700 Subject: [PATCH 23/36] Update CMakeLists.txt --- test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 10a3b88363c9..9a005ca91c86 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -42,6 +42,7 @@ if (MSVC AND WIN32) set(FMT_CUSTOM_MSVC_EH /EHsc) else () set(FMT_CUSTOM_MSVC_EH) + endif () endif () target_compile_options(gmock PUBLIC ${FMT_CUSTOM_MSVC_EH}) endif () From 03d76000fdea60975d7dc1852b568451a1d33b31 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 18:39:24 +0700 Subject: [PATCH 24/36] Not sure about MSVC, test travis again --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8849b203140a..544f3ca6f1d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,7 +164,7 @@ endif () # Insert FMT_MSVC_EH if user provides. # If not, default to /EHsc in clang target msvc. -if (MSVC AND WIN32) +if (MSVC) if (FMT_MSVC_EH) set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) else () From b6db4b8a26411416aa9c339caf0115c71be5eb81 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Thu, 9 May 2019 18:48:28 +0700 Subject: [PATCH 25/36] Turns out that I misunderstood MSVC --- test/CMakeLists.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9a005ca91c86..58c62f0e63f0 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,18 +21,17 @@ if (NOT SUPPORTS_VARIADIC_TEMPLATES) target_compile_definitions(gmock PUBLIC GTEST_LANG_CXX11=0) endif () -# Workaround a bug in implementation of variadic templates in MSVC11. if (MSVC) + # Workaround a bug in implementation of variadic templates in MSVC11. target_compile_definitions(gmock PUBLIC _VARIADIC_MAX=10) -endif () - -if (MSVC AND WIN32) + # Disable MSVC warnings of _CRT_INSECURE_DEPRECATE functions. target_compile_definitions(gmock PUBLIC _CRT_SECURE_NO_WARNINGS) if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # Disable MSVC warnings of POSIX functions. target_compile_options(gmock PUBLIC -Wno-deprecated-declarations) endif () + # Insert FMT_MSVC_EH if user provides. # if not, default to /EHsc in clang target msvc. if (FMT_MSVC_EH) From 9155a22af6da8b01bb939b0adbd6bed2befdbfaf Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Fri, 10 May 2019 17:38:57 +0700 Subject: [PATCH 26/36] Add conditional defined FMT_MAYBE_UNUSED --- include/fmt/core.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/include/fmt/core.h b/include/fmt/core.h index 0d1b55236383..7856ea21cbf4 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -80,6 +80,16 @@ # define FMT_CONSTEXPR11 #endif +#ifndef FMT_USE_MAYBE_UNUSED +# define FMT_USE_MAYBE_UNUSED \ + (__cplusplus >= 201703L) +#endif +#if FMT_USE_MAYBE_UNUSED +# define FMT_MAYBE_UNUSED [[maybe_unused]] +#else +# define FMT_MAYBE_UNUSED +#endif + #ifndef FMT_OVERRIDE # if FMT_HAS_FEATURE(cxx_override) || \ (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900 From eaaa44c3cee28fce1262d345852f890b4780010e Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Fri, 10 May 2019 17:39:05 +0700 Subject: [PATCH 27/36] Use [[maybe_unused]] to suppress -Wunused-variable --- test/format-test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index 20ff737f6401..7a1285b60af6 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2540,9 +2540,9 @@ TEST(FormatTest, EmphasisNonHeaderOnly) { TEST(FormatTest, CharTraitsIsNotAmbiguous) { // Test that we don't inject internal names into the std namespace. using namespace std; - char_traits::char_type c; + FMT_MAYBE_UNUSED char_traits::char_type c; #if __cplusplus >= 201103L std::string s; - auto lval = begin(s); + FMT_MAYBE_UNUSED auto lval = begin(s); #endif } From 02e472d63a606c9a2cb204d41e82461d55c3279a Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sat, 11 May 2019 18:50:18 +0700 Subject: [PATCH 28/36] Delete selective adding /EHsc. Leave it to users. MSVC by default doesn't enable /EHsc either. Exception setting depends on user configurations. --- test/CMakeLists.txt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 58c62f0e63f0..7bbe63a5ca96 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -31,19 +31,6 @@ if (MSVC) # Disable MSVC warnings of POSIX functions. target_compile_options(gmock PUBLIC -Wno-deprecated-declarations) endif () - - # Insert FMT_MSVC_EH if user provides. - # if not, default to /EHsc in clang target msvc. - if (FMT_MSVC_EH) - set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) - else () - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(FMT_CUSTOM_MSVC_EH /EHsc) - else () - set(FMT_CUSTOM_MSVC_EH) - endif () - endif () - target_compile_options(gmock PUBLIC ${FMT_CUSTOM_MSVC_EH}) endif () # GTest doesn't detect with clang. From f1fd5accaf482656fb54c5c3ec78fd4644848e2e Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sat, 11 May 2019 18:50:23 +0700 Subject: [PATCH 29/36] Rollback MSVC by default doesn't enable /EHsc also. Just keep it most simple. --- CMakeLists.txt | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 544f3ca6f1d0..ee0142c5ee48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,21 +162,6 @@ if (FMT_PEDANTIC) target_compile_options(fmt PRIVATE ${PEDANTIC_COMPILE_FLAGS}) endif () -# Insert FMT_MSVC_EH if user provides. -# If not, default to /EHsc in clang target msvc. -if (MSVC) - if (FMT_MSVC_EH) - set(FMT_CUSTOM_MSVC_EH ${FMT_MSVC_EH}) - else () - if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(FMT_CUSTOM_MSVC_EH /EHsc) - else () - set(FMT_CUSTOM_MSVC_EH) - endif () - endif () - target_compile_options(fmt PRIVATE ${FMT_CUSTOM_MSVC_EH}) -endif () - target_compile_features(fmt INTERFACE ${FMT_REQUIRED_FEATURES}) target_include_directories(fmt PUBLIC From 659567c4d597e245bad5d371f16fbc640a278a7d Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sat, 11 May 2019 18:57:18 +0700 Subject: [PATCH 30/36] Because grisu_format does "import" when `sizeof(Double) == sizeof(uint64_t)` So we have to "export" here also. --- include/fmt/format-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index d8956822c799..e163f333e515 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -683,7 +683,7 @@ template struct grisu_shortest_handler { }; template -FMT_FUNC bool grisu_format(Double value, buffer& buf, int precision, +FMT_FUNC FMT_API bool grisu_format(Double value, buffer& buf, int precision, unsigned options, int& exp) { FMT_ASSERT(value >= 0, "value is negative"); bool fixed = (options & grisu_options::fixed) != 0; From 889f904aa588b4dcf3ea41bce10efb60d2467b18 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sat, 11 May 2019 23:37:55 +0700 Subject: [PATCH 31/36] Rollback --- include/fmt/core.h | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/include/fmt/core.h b/include/fmt/core.h index 7856ea21cbf4..0d1b55236383 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -80,16 +80,6 @@ # define FMT_CONSTEXPR11 #endif -#ifndef FMT_USE_MAYBE_UNUSED -# define FMT_USE_MAYBE_UNUSED \ - (__cplusplus >= 201703L) -#endif -#if FMT_USE_MAYBE_UNUSED -# define FMT_MAYBE_UNUSED [[maybe_unused]] -#else -# define FMT_MAYBE_UNUSED -#endif - #ifndef FMT_OVERRIDE # if FMT_HAS_FEATURE(cxx_override) || \ (FMT_GCC_VERSION >= 408 && FMT_HAS_GXX_CXX11) || FMT_MSC_VER >= 1900 From 8b3227f97d4c503346ce8bb64bda339e99943f9f Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sat, 11 May 2019 23:38:02 +0700 Subject: [PATCH 32/36] (void)X; suppresses -Wunused-variable --- test/format-test.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/format-test.cc b/test/format-test.cc index 7a1285b60af6..c1b409de7aae 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2540,9 +2540,11 @@ TEST(FormatTest, EmphasisNonHeaderOnly) { TEST(FormatTest, CharTraitsIsNotAmbiguous) { // Test that we don't inject internal names into the std namespace. using namespace std; - FMT_MAYBE_UNUSED char_traits::char_type c; + char_traits::char_type c; + (void)c; #if __cplusplus >= 201103L std::string s; - FMT_MAYBE_UNUSED auto lval = begin(s); + auto lval = begin(s); + (void)lval; #endif } From 6d0343fe5a7c39b254a592d699fb31129b724cd8 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sat, 11 May 2019 23:42:11 +0700 Subject: [PATCH 33/36] bool grisu_format is not supposed to be imported/exported when sizeof(Double) == sizeof(uint64_t) --- include/fmt/format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 0c462d135b2f..212f559727b1 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1122,7 +1122,7 @@ enum { // Formats value using the Grisu algorithm: // https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf template -FMT_API bool grisu_format(Double, buffer&, int, unsigned, int&); +bool grisu_format(Double, buffer&, int, unsigned, int&); template inline bool grisu_format(Double, buffer&, int, unsigned, int&) { return false; From 166b79dd088741c3ebd4504027b73d6765bafdb9 Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sat, 11 May 2019 23:48:15 +0700 Subject: [PATCH 34/36] grisu_format is not supposed to be imported/exported When sizeof(Double) == sizeof(uint64_t) --- include/fmt/format-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index e163f333e515..d8956822c799 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -683,7 +683,7 @@ template struct grisu_shortest_handler { }; template -FMT_FUNC FMT_API bool grisu_format(Double value, buffer& buf, int precision, +FMT_FUNC bool grisu_format(Double value, buffer& buf, int precision, unsigned options, int& exp) { FMT_ASSERT(value >= 0, "value is negative"); bool fixed = (options & grisu_options::fixed) != 0; From 3b4928a8f49c363dcba20f0c329fd780938d7a9d Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sun, 12 May 2019 00:13:30 +0700 Subject: [PATCH 35/36] Rollback --- include/fmt/format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 212f559727b1..0c462d135b2f 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1122,7 +1122,7 @@ enum { // Formats value using the Grisu algorithm: // https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf template -bool grisu_format(Double, buffer&, int, unsigned, int&); +FMT_API bool grisu_format(Double, buffer&, int, unsigned, int&); template inline bool grisu_format(Double, buffer&, int, unsigned, int&) { return false; From e422dada0aa2579000dd3c0fc3877c977273679e Mon Sep 17 00:00:00 2001 From: denchat <19730041+denchat@users.noreply.github.com> Date: Sun, 12 May 2019 00:16:02 +0700 Subject: [PATCH 36/36] Remove FMT_FUNC, mark FMT_API to export --- include/fmt/format-inl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/fmt/format-inl.h b/include/fmt/format-inl.h index d8956822c799..9e77b4e087c3 100644 --- a/include/fmt/format-inl.h +++ b/include/fmt/format-inl.h @@ -683,7 +683,7 @@ template struct grisu_shortest_handler { }; template -FMT_FUNC bool grisu_format(Double value, buffer& buf, int precision, +FMT_API bool grisu_format(Double value, buffer& buf, int precision, unsigned options, int& exp) { FMT_ASSERT(value >= 0, "value is negative"); bool fixed = (options & grisu_options::fixed) != 0;