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

Clang keeps complain it ignores __declspec(dllexport) of basic_data<void> template instantitation definition in format.cc #2220

Merged
merged 13 commits into from
Apr 12, 2021

Conversation

denchat
Copy link
Contributor

@denchat denchat commented Apr 8, 2021

Remove __declspec(dllexport) from the definition
and add template instantiation declaration (aka extern) in format.h

I'm not sure the added position is correct, please check if it's okey.

denchat added 3 commits April 9, 2021 01:44
Clang keeps complain it ignores __declspec(dllexport) in format.cc's instantiation of "detail::basic_data<void>;"

```
C:/Users/User/AppData/Roaming/fmt-master/src/format.cc:58:17: warning: 'dllexport' attribute ignored on explicit instantiation definition [-Wignored-attributes]
template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
                ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/core.h:228:37: note: expanded from macro 'FMT_INSTANTIATION_DEF_API'
#  define FMT_INSTANTIATION_DEF_API FMT_API
                                    ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/core.h:210:32: note: expanded from macro 'FMT_API'
#    define FMT_API __declspec(dllexport)
                               ^
1 warning generated.
```

I guess we have to make an explicit instantiation definition of `basic_data<void>` in format.cc (without `__declspec(dllexport)` )
and make an explicit instantiation declaration (aka `extern template`) in format.h instead
Add the template instantiation **declaration** of `basic_data<void>`
the the template instantiation **definition** is in `format.cc`
@denchat
Copy link
Contributor Author

denchat commented Apr 8, 2021

Or should I move FMT_INSTANTIATION_DEF_API deletion into the WIN32 check branch (above current position) instead ?

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you post the full warning message that you get? Also there are some CI failures.

denchat added 2 commits April 10, 2021 23:04
Try remove FMT_INSTANTIATION_DEF_API from extern template
Fix removing the entire declaration because at line 999 there is one.
CI Error in macOS.
@denchat
Copy link
Contributor Author

denchat commented Apr 10, 2021

Could you post the full warning message that you get? Also there are some CI failures.

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.4
-- 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
[3/51] Building CXX object CMakeFiles/fmt.dir/src/format.cc.obj
C:/Users/User/AppData/Roaming/fmt-master/src/format.cc:58:17: warning: 'dllexport' attribute ignored on explicit instantiation definition [-Wignored-attributes]
template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
                ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/core.h:228:37: note: expanded from macro 'FMT_INSTANTIATION_DEF_API'
#  define FMT_INSTANTIATION_DEF_API FMT_API
                                    ^
C:/Users/User/AppData/Roaming/fmt-master/include\fmt/core.h:210:32: note: expanded from macro 'FMT_API'
#    define FMT_API __declspec(dllexport)
                               ^
1 warning generated.

By the way, this still does not succeed. It fails on compile-test.cc somehow.
#2223

However it's perhaps a clang 12 or mingw64 bug.

@@ -206,6 +206,7 @@

#if !defined(FMT_HEADER_ONLY) && defined(_WIN32)
# define FMT_CLASS_API FMT_MSC_WARNING(suppress : 4275)
# define FMT_INSTANTIATION_DEF_API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot just remove __declspec(dllexport) because it will break a shared library. Instead it should be applied to a declaration that can be added to format.cc.

@denchat
Copy link
Contributor Author

denchat commented Apr 12, 2021

It seems there might has been some changes.

[MinGW] Fix dllexport of explicit template instantiation
https://reviews.llvm.org/D61118

To fix

  • Mark only at the extern template, not the definition
  • Restore behavior of FMT_INSTANTIATION_DEF_API to follow FMT_API

denchat added 3 commits April 12, 2021 11:53
FMT_INSTANTIATION_DEF_API follows FMT_API
D61118 : make dllexport on extern template, not the instantiation definition in format.cc

[MinGW] Fix dllexport of explicit template instantiation
https://reviews.llvm.org/D61118
Move FMT_INSTANTIATION_DEF_API  to the declaration in format.h

[MinGW] Fix dllexport of explicit template instantiation
https://reviews.llvm.org/D61118
@denchat
Copy link
Contributor Author

denchat commented Apr 12, 2021

More over, FMT_INSTANTIATION_DEF_API shall be considered to be renamed.
what about FMT_INSTANTIATION_DECL_API ?
Is it okey?

@vitaut
Copy link
Contributor

vitaut commented Apr 12, 2021

More over, FMT_INSTANTIATION_DEF_API shall be considered to be renamed.
what about FMT_INSTANTIATION_DECL_API ?
Is it okey?

Sure

@@ -55,7 +55,7 @@ vformat_to(buffer<char>&, string_view,
type_identity_t<char>>>);
} // namespace detail

template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
template struct detail::basic_data<void>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a short comment saying that clang doesn't allow __declspec(dllexport) here.

denchat added 3 commits April 12, 2021 22:15
Rename FMT_INSTANTIATION_DEF_API to FMT_INSTANTIATION_DECL_API

[MinGW] Fix dllexport of explicit template instantiation
https://reviews.llvm.org/D61118
Rename FMT_INSTANTIATION_DEF_API to FMT_INSTANTIATION_DECL_API

[MinGW] Fix dllexport of explicit template instantiation
https://reviews.llvm.org/D61118
Add a comment that clang now doesn't allow dllexport on template instantiation definitions.
Mark them on tempalte instantiation declarations instead (in format.h).

[MinGW] Fix dllexport of explicit template instantiation
https://reviews.llvm.org/D61118
@denchat
Copy link
Contributor Author

denchat commented Apr 12, 2021

A comment is added but please feel free to edit it.

Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one remaining nit.

src/format.cc Outdated
@@ -55,7 +55,8 @@ vformat_to(buffer<char>&, string_view,
type_identity_t<char>>>);
} // namespace detail

template struct FMT_INSTANTIATION_DEF_API detail::basic_data<void>;
// Clang doesn't allow dllexport on template instantiation definitions (LLVM D61118)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Please add . at the end of the sentence and apply clang-format.

@vitaut vitaut merged commit 42eccac into fmtlib:master Apr 12, 2021
@vitaut
Copy link
Contributor

vitaut commented Apr 12, 2021

Thanks

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