Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-Wattributes visibility warning with some GCC versions #1975

Merged
merged 5 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ matrix:
packages:
- g++-8

# ARM g++ 6 on Linux with C++14
alexezeder marked this conversation as resolved.
Show resolved Hide resolved
- 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
Expand Down
29 changes: 18 additions & 11 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -3198,17 +3198,24 @@ FMT_CONSTEXPR basic_string_view<Char> 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<decltype(s[0])>; \
FMT_MAYBE_UNUSED FMT_CONSTEXPR \
operator fmt::basic_string_view<char_type>() const { \
return fmt::detail::compile_string_to_view<char_type>(s); \
} \
}; \
return FMT_COMPILE_STRING(); \
#if defined(FMT_GCC_VERSION) && FMT_GCC_VERSION >= 400
alexezeder marked this conversation as resolved.
Show resolved Hide resolved
# define FMT_COMPILE_STRING_VISIBILITY_ATTRIBUTE \
alexezeder marked this conversation as resolved.
Show resolved Hide resolved
__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 { \
alexezeder marked this conversation as resolved.
Show resolved Hide resolved
using char_type = fmt::remove_cvref_t<decltype(s[0])>; \
FMT_MAYBE_UNUSED FMT_CONSTEXPR \
operator fmt::basic_string_view<char_type>() const { \
return fmt::detail::compile_string_to_view<char_type>(s); \
} \
}; \
return FMT_COMPILE_STRING(); \
}()

/**
Expand Down
3 changes: 3 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
alexezeder marked this conversation as resolved.
Show resolved Hide resolved
endif()
target_include_directories(${name} SYSTEM PUBLIC gtest gmock)
add_test(NAME ${name} COMMAND ${name})
endfunction()
Expand Down