From 574cd279bb87b6985e46932f0f73e7d087d107d4 Mon Sep 17 00:00:00 2001 From: Alexey Ochapov Date: Tue, 3 Nov 2020 22:34:04 +0300 Subject: [PATCH 1/5] temp: fail build on gcc 6 --- .travis.yml | 14 ++++++++++++++ test/CMakeLists.txt | 3 +++ 2 files changed, 17 insertions(+) diff --git a/.travis.yml b/.travis.yml index ff9d167b61fc..b2cfc8a29d99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,6 +58,20 @@ matrix: packages: - g++-8 + # ARM g++ 6 on Linux with C++14 + - env: COMPILER=g++-6 BUILD=Debug STANDARD=14 + compiler: gcc + arch: arm64 + os: linux + dist: xenial + addons: + apt: + update: true + sources: + - ubuntu-toolchain-r-test + packages: + - g++-6 + # Apple clang on OS X with C++14 - env: BUILD=Debug STANDARD=14 compiler: clang diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7ae5659de6a5..64e4d0378140 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -83,6 +83,9 @@ function(add_fmt_test name) if (FMT_WERROR) target_compile_options(${name} PRIVATE ${WERROR_FLAG}) endif () + if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + target_compile_options(${name} PRIVATE -fvisibility=hidden -Werror=attributes) + endif() target_include_directories(${name} SYSTEM PUBLIC gtest gmock) add_test(NAME ${name} COMMAND ${name}) endfunction() From fe11777d7873ab2c73fcaf91536cdb9edfafea20 Mon Sep 17 00:00:00 2001 From: Alexey Ochapov Date: Wed, 4 Nov 2020 01:04:12 +0300 Subject: [PATCH 2/5] actual fix to eliminate warnings --- include/fmt/format.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index ea45429f17cb..87c62fed4f6e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3198,17 +3198,24 @@ FMT_CONSTEXPR basic_string_view compile_string_to_view( return {s.data(), s.size()}; } -#define FMT_STRING_IMPL(s, base) \ - [] { \ - /* Use a macro-like name to avoid shadowing warnings. */ \ - struct FMT_COMPILE_STRING : base { \ - using char_type = fmt::remove_cvref_t; \ - FMT_MAYBE_UNUSED FMT_CONSTEXPR \ - operator fmt::basic_string_view() const { \ - return fmt::detail::compile_string_to_view(s); \ - } \ - }; \ - return FMT_COMPILE_STRING(); \ +#if defined(FMT_GCC_VERSION) && FMT_GCC_VERSION >= 400 +# define FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE \ + __attribute__((visibility("hidden"))) +#else +# define FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE +#endif + +#define FMT_STRING_IMPL(s, base) \ + [] { \ + /* Use a macro-like name to avoid shadowing warnings. */ \ + struct FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE FMT_COMPILE_STRING : base { \ + using char_type = fmt::remove_cvref_t; \ + FMT_MAYBE_UNUSED FMT_CONSTEXPR \ + operator fmt::basic_string_view() const { \ + return fmt::detail::compile_string_to_view(s); \ + } \ + }; \ + return FMT_COMPILE_STRING(); \ }() /** From 535a4e5f9b518b710d664de204e08da2a61dba51 Mon Sep 17 00:00:00 2001 From: Alexey Ochapov Date: Wed, 4 Nov 2020 18:41:10 +0300 Subject: [PATCH 3/5] simplify check for FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE --- 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 87c62fed4f6e..7de07422ca0e 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -3198,7 +3198,7 @@ FMT_CONSTEXPR basic_string_view compile_string_to_view( return {s.data(), s.size()}; } -#if defined(FMT_GCC_VERSION) && FMT_GCC_VERSION >= 400 +#if FMT_GCC_VERSION # define FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE \ __attribute__((visibility("hidden"))) #else From f480d30ea6c83c612bee9a420b80e92b4df6f0db Mon Sep 17 00:00:00 2001 From: Alexey Ochapov Date: Wed, 4 Nov 2020 18:41:45 +0300 Subject: [PATCH 4/5] Revert "temp: fail build on gcc 6" This reverts commit 574cd279 --- .travis.yml | 14 -------------- test/CMakeLists.txt | 3 --- 2 files changed, 17 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2cfc8a29d99..ff9d167b61fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,20 +58,6 @@ matrix: packages: - g++-8 - # ARM g++ 6 on Linux with C++14 - - env: COMPILER=g++-6 BUILD=Debug STANDARD=14 - compiler: gcc - arch: arm64 - os: linux - dist: xenial - addons: - apt: - update: true - sources: - - ubuntu-toolchain-r-test - packages: - - g++-6 - # Apple clang on OS X with C++14 - env: BUILD=Debug STANDARD=14 compiler: clang diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 64e4d0378140..7ae5659de6a5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -83,9 +83,6 @@ function(add_fmt_test name) if (FMT_WERROR) target_compile_options(${name} PRIVATE ${WERROR_FLAG}) endif () - if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") - target_compile_options(${name} PRIVATE -fvisibility=hidden -Werror=attributes) - endif() target_include_directories(${name} SYSTEM PUBLIC gtest gmock) add_test(NAME ${name} COMMAND ${name}) endfunction() From f74736dd143843da3dc15103ffcdaa6d8d20cc39 Mon Sep 17 00:00:00 2001 From: Alexey Ochapov Date: Wed, 4 Nov 2020 23:47:25 +0300 Subject: [PATCH 5/5] FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE -> FMT_GCC_VISIBILITY_HIDDEN, add comments --- include/fmt/format.h | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 7de07422ca0e..537bd9c49c4d 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -69,6 +69,13 @@ # define FMT_NOINLINE #endif +// Special definition specific to GCC only +#if FMT_GCC_VERSION +# define FMT_GCC_VISIBILITY_HIDDEN __attribute__((visibility("hidden"))) +#else +# define FMT_GCC_VISIBILITY_HIDDEN +#endif + #if __cplusplus == 201103L || __cplusplus == 201402L # if defined(__INTEL_COMPILER) || defined(__PGI) # define FMT_FALLTHROUGH @@ -3198,24 +3205,19 @@ FMT_CONSTEXPR basic_string_view compile_string_to_view( return {s.data(), s.size()}; } -#if FMT_GCC_VERSION -# define FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE \ - __attribute__((visibility("hidden"))) -#else -# define FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE -#endif - -#define FMT_STRING_IMPL(s, base) \ - [] { \ - /* Use a macro-like name to avoid shadowing warnings. */ \ - struct FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE FMT_COMPILE_STRING : base { \ - using char_type = fmt::remove_cvref_t; \ - FMT_MAYBE_UNUSED FMT_CONSTEXPR \ - operator fmt::basic_string_view() const { \ - return fmt::detail::compile_string_to_view(s); \ - } \ - }; \ - return FMT_COMPILE_STRING(); \ +#define FMT_STRING_IMPL(s, base) \ + [] { \ + /* Use a hidden visibility as workaround for some GCC, see */ \ + /* https://github.com/fmtlib/fmt/issues/1973 for details */ \ + /* Use a macro-like name to avoid shadowing warnings. */ \ + struct FMT_GCC_VISIBILITY_HIDDEN FMT_COMPILE_STRING : base { \ + using char_type = fmt::remove_cvref_t; \ + FMT_MAYBE_UNUSED FMT_CONSTEXPR \ + operator fmt::basic_string_view() const { \ + return fmt::detail::compile_string_to_view(s); \ + } \ + }; \ + return FMT_COMPILE_STRING(); \ }() /**