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

Suppressing clang complain "forward declaration" #2241

Closed
wants to merge 9 commits into from

Conversation

denchat
Copy link
Contributor

@denchat denchat commented Apr 17, 2021

Clang complains about "forward declaration of template entity" of all basic_data<>'s members that do not have definitions in format.h

C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: warning: instantiation of variable 'fmt::detail::basic_data<>::powers_of_10_64' required here, but no definition is available [-Wundefined-var-template]
  static const uint64_t powers_of_10_64[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::powers_of_10_64' is explicitly instantiated in another translation unit

Clang complains about "forward declaration of template entity" of all basic_data<>'s members that do not have definitions in `format.h`

```
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: warning: instantiation of variable 'fmt::detail::basic_data<>::powers_of_10_64' required here, but no definition is available [-Wundefined-var-template]
  static const uint64_t powers_of_10_64[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::powers_of_10_64' is explicitly instantiated in another translation unit
```
Remove FMT_API.
Try hiding the extern template's members declaration from msvc instead.
-  Added FMT_INSTANTIATION_DECL_API
-  Added non-msvc filter
-  Added msvc non-export filter
Added FMT_INSTANTIATION_DEF_API in definition in format-inl.h
@denchat
Copy link
Contributor Author

denchat commented Apr 18, 2021

I'm not sure whether FMT_INSTANTIATION_DECL_API added is in fact redundant.
Commit abb5eb4 seems fine without it.

I can remove FMT_INSTANTIATION_DECL_API if prefered.

@vitaut
Copy link
Contributor

vitaut commented Apr 18, 2021

I can remove FMT_INSTANTIATION_DECL_API if prefered.

Please do.

@vitaut
Copy link
Contributor

vitaut commented Apr 19, 2021

Is extern template struct basic_data<void> not enough? Do we really need to declare every member?

@denchat
Copy link
Contributor Author

denchat commented Apr 20, 2021

Is extern template struct basic_data not enough?

It seems clang complains only at the data members that do not have definition, e.g. powers_of_10_64[], in the translation unit format.h.

In contrast, ones that are already defined, e.g. log10_2_significand, do not get complained.

C:\users\User\AppData\Roaming\fmt>cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM="C:/Program Files (x86)/Ninja/ninja.exe" -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_CXX_STANDARD=23 -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang++.exe" -DCMAKE_CXX_FLAGS="-fuse-ld=lld --target=x86_64-w64-windows-gnu --driver-mode=g++ -O3 -std=gnu++2b -static-libgcc -static-libstdc++ -fconstexpr-backtrace-limit=0 -lwinpthread -DNDEBUG -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_STDIO_ISO_WIDE_SPECIFIERS -Wno-unused-command-line-argument" -DCMAKE_CXX_LINK_EXECUTABLE="C:/Program Files/LLVM/bin/lld.exe" -DBUILD_SHARED_LIBS=YES -DFMT_INSTALL=NO -DFMT_DOC=NO -DFMT_TEST=YES "C:/Users/User/AppData/Roaming/fmt-master"
-- CMake version: 3.20.0
-- The CXX compiler identification is Clang 12.0.5
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/LLVM/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Version: 7.1.3
-- Build type: Release
-- CXX_STANDARD: 23
-- Performing Test SUPPORTS_USER_DEFINED_LITERALS
-- Performing Test SUPPORTS_USER_DEFINED_LITERALS - Success
-- Performing Test FMT_HAS_VARIANT
-- Performing Test FMT_HAS_VARIANT - Success
-- Required features: cxx_variadic_templates
-- Performing Test HAS_NULLPTR_WARNING
-- Performing Test HAS_NULLPTR_WARNING - Success
-- Looking for _strtod_l
-- Looking for _strtod_l - found
-- Performing Test FMT_HAS_MBIG_OBJ
-- Performing Test FMT_HAS_MBIG_OBJ - Failed
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Performing Test HAVE_FNO_DELETE_NULL_POINTER_CHECKS
-- Performing Test HAVE_FNO_DELETE_NULL_POINTER_CHECKS - Success
-- FMT_PEDANTIC: OFF
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/User/AppData/Roaming/fmt

C:\users\User\AppData\Roaming\fmt>ninja -j 2
[1/51] Building CXX object CMakeFiles/fmt.dir/src/os.cc.obj
In file included from C:/Users/User/AppData/Roaming/fmt-master/src/os.cc:13:
In file included from C:/Users/User/AppData/Roaming/fmt-master/include\fmt/os.h:21:
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: warning: instantiation of variable 'fmt::detail::basic_data<>::powers_of_10_64' required here, but no definition is available [-Wundefined-var-template]
  static const uint64_t powers_of_10_64[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:956:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::powers_of_10_64' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:957:25: warning: instantiation of variable 'fmt::detail::basic_data<>::zero_or_powers_of_10_32_new' required here, but no definition is available [-Wundefined-var-template]
  static const uint32_t zero_or_powers_of_10_32_new[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:957:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:957:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::zero_or_powers_of_10_32_new' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:958:25: warning: instantiation of variable 'fmt::detail::basic_data<>::zero_or_powers_of_10_64_new' required here, but no definition is available [-Wundefined-var-template]
  static const uint64_t zero_or_powers_of_10_64_new[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:958:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:958:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::zero_or_powers_of_10_64_new' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:959:25: warning: instantiation of variable 'fmt::detail::basic_data<>::grisu_pow10_significands' required here, but no definition is available [-Wundefined-var-template]
  static const uint64_t grisu_pow10_significands[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:959:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:959:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::grisu_pow10_significands' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:960:24: warning: instantiation of variable 'fmt::detail::basic_data<>::grisu_pow10_exponents' required here, but no definition is available [-Wundefined-var-template]
  static const int16_t grisu_pow10_exponents[];
                       ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:960:24: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:960:24: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::grisu_pow10_exponents' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:961:46: warning: instantiation of variable 'fmt::detail::basic_data<>::divtest_table_for_pow5_32' required here, but no definition is available [-Wundefined-var-template]
  static const divtest_table_entry<uint32_t> divtest_table_for_pow5_32[];
                                             ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:961:46: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:961:46: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::divtest_table_for_pow5_32' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:962:46: warning: instantiation of variable 'fmt::detail::basic_data<>::divtest_table_for_pow5_64' required here, but no definition is available [-Wundefined-var-template]
  static const divtest_table_entry<uint64_t> divtest_table_for_pow5_64[];
                                             ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:962:46: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:962:46: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::divtest_table_for_pow5_64' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:963:25: warning: instantiation of variable 'fmt::detail::basic_data<>::dragonbox_pow10_significands_64' required here, but no definition is available [-Wundefined-var-template]
  static const uint64_t dragonbox_pow10_significands_64[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:963:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:963:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::dragonbox_pow10_significands_64' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:964:32: warning: instantiation of variable 'fmt::detail::basic_data<>::dragonbox_pow10_significands_128' required here, but no definition is available [-Wundefined-var-template]
  static const uint128_wrapper dragonbox_pow10_significands_128[];
                               ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:964:32: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:964:32: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::dragonbox_pow10_significands_128' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:968:25: warning: instantiation of variable 'fmt::detail::basic_data<>::powers_of_5_64' required here, but no definition is available [-Wundefined-var-template]
  static const uint64_t powers_of_5_64[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:968:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:968:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::powers_of_5_64' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:969:25: warning: instantiation of variable 'fmt::detail::basic_data<>::dragonbox_pow10_recovery_errors' required here, but no definition is available [-Wundefined-var-template]
  static const uint32_t dragonbox_pow10_recovery_errors[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:969:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:969:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::dragonbox_pow10_recovery_errors' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:973:27: warning: instantiation of variable 'fmt::detail::basic_data<>::digits' required here, but no definition is available [-Wundefined-var-template]
  static const digit_pair digits[];
                          ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:973:27: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:973:27: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::digits' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:975:21: warning: instantiation of variable 'fmt::detail::basic_data<>::foreground_color' required here, but no definition is available [-Wundefined-var-template]
  static const char foreground_color[];
                    ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:975:21: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:975:21: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::foreground_color' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:976:21: warning: instantiation of variable 'fmt::detail::basic_data<>::background_color' required here, but no definition is available [-Wundefined-var-template]
  static const char background_color[];
                    ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:976:21: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:976:21: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::background_color' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:977:21: warning: instantiation of variable 'fmt::detail::basic_data<>::reset_color' required here, but no definition is available [-Wundefined-var-template]
  static const char reset_color[5];
                    ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:977:21: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:977:21: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::reset_color' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:978:24: warning: instantiation of variable 'fmt::detail::basic_data<>::wreset_color' required here, but no definition is available [-Wundefined-var-template]
  static const wchar_t wreset_color[5];
                       ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:978:24: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:978:24: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::wreset_color' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:979:21: warning: instantiation of variable 'fmt::detail::basic_data<>::signs' required here, but no definition is available [-Wundefined-var-template]
  static const char signs[];
                    ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:979:21: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:979:21: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::signs' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:986:25: warning: instantiation of variable 'fmt::detail::basic_data<>::zero_or_powers_of_10_32' required here, but no definition is available [-Wundefined-var-template]
  static const uint32_t zero_or_powers_of_10_32[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:986:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:986:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::zero_or_powers_of_10_32' is explicitly instantiated in another translation unit
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:987:25: warning: instantiation of variable 'fmt::detail::basic_data<>::zero_or_powers_of_10_64' required here, but no definition is available [-Wundefined-var-template]
  static const uint64_t zero_or_powers_of_10_64[];
                        ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:987:25: note: forward declaration of template entity is here
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/format.h:987:25: note: add an explicit instantiation declaration to suppress this warning if 'fmt::detail::basic_data<>::zero_or_powers_of_10_64' is explicitly instantiated in another translation unit
19 warnings generated.

If you think clang is overreacting beyond the standard specified, we can add -Wno-undefined-var-template flag instead.
What do you think?

@vitaut
Copy link
Contributor

vitaut commented Apr 23, 2021

Thinking more of it, we should just move most static data to functions where it is used and make the rest constexpr. This will eliminate the need to export anything (c47f211). Thanks for looking into it anyway.

@vitaut vitaut closed this Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants