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

Trying to suppress all clang-target-msvc test warning in CMAKE and other misc fixes #1151

Merged
merged 36 commits into from
May 11, 2019
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c575d56
Fix conditional `char8_t` from `format.h` and fix `-Wunused-result` o…
denchat May 8, 2019
28588a9
Suppress `-Winconsistent-dllimport` when in clang-target-msvc
denchat May 8, 2019
abb3050
Suppress warning _CRT_SECURE_NO_WARNINGS in MSVC and -Wdeprecated-dec…
denchat May 8, 2019
63d6445
Turn on exceptions automatically in MSVC
denchat May 8, 2019
c8cbf57
Use 'using' to provide char8_t type if neccessary as Victor's suggestion
denchat May 9, 2019
d75c98b
Narrowing scope to clang-target-msvc for mirroring cl default /EHsc
denchat May 9, 2019
d7b83ff
Narrowing /EHsc to clang-target-msvc only
denchat May 9, 2019
073571a
missing that semicolon!
denchat May 9, 2019
eb420be
Receive FMT_MSVC_EH from user
denchat May 9, 2019
b17216a
Receive FMT_MSVC_EH from user
denchat May 9, 2019
e7e48c3
Fix excessing parenthesis
denchat May 9, 2019
c079096
Fix excessing parenthesis
denchat May 9, 2019
9d0de74
Fix AppleClang match
denchat May 9, 2019
6593a07
Fix AppleClang match
denchat May 9, 2019
bdc4929
Try workaround with WIN32
denchat May 9, 2019
28b559e
Try workaround with WIN32
denchat May 9, 2019
133af4a
Because TravisCI evaluates MSVC true in linux and apple
denchat May 9, 2019
39a140a
Because TravisCI evaluates MSVC true in linux and apple
denchat May 9, 2019
032ac28
Bring _VARIADIC_MAX=10 out of MSVC AND WIN32 context
denchat May 9, 2019
8d8f7b1
gmock PUBLIC
denchat May 9, 2019
473ccd0
Update CMakeLists.txt
denchat May 9, 2019
ade161d
Update CMakeLists.txt
denchat May 9, 2019
ff44d1a
Update CMakeLists.txt
denchat May 9, 2019
03d7600
Not sure about MSVC, test travis again
denchat May 9, 2019
b6db4b8
Turns out that I misunderstood MSVC
denchat May 9, 2019
9155a22
Add conditional defined FMT_MAYBE_UNUSED
denchat May 10, 2019
eaaa44c
Use [[maybe_unused]] to suppress -Wunused-variable
denchat May 10, 2019
02e472d
Delete selective adding /EHsc. Leave it to users.
denchat May 11, 2019
f1fd5ac
Rollback
denchat May 11, 2019
659567c
Because grisu_format does "import" when `sizeof(Double) == sizeof(uin…
denchat May 11, 2019
889f904
Rollback
denchat May 11, 2019
8b3227f
(void)X; suppresses -Wunused-variable
denchat May 11, 2019
6d0343f
bool grisu_format is not supposed to be imported/exported
denchat May 11, 2019
166b79d
grisu_format is not supposed to be imported/exported
denchat May 11, 2019
3b4928a
Rollback
denchat May 11, 2019
e422dad
Remove FMT_FUNC, mark FMT_API to export
denchat May 11, 2019
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
10 changes: 10 additions & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/fmt/format-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ template <int GRISU_VERSION> struct grisu_shortest_handler {
};

template <typename Double, FMT_ENABLE_IF_T(sizeof(Double) == sizeof(uint64_t))>
FMT_FUNC bool grisu_format(Double value, buffer<char>& buf, int precision,
FMT_FUNC FMT_API bool grisu_format(Double value, buffer<char>& buf, int precision,
Copy link
Contributor

Choose a reason for hiding this comment

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

FMT_API shouldn't be here because it's an internal symbol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In DLL mode, grisu_format is refered by custom-formatter-test.cc.

C:\Users\User\AppData\Roaming\fmt>ninja -j 2
[3/47] Linking CXX shared library bin\fmt.dll
   Creating library fmt.lib and object fmt.exp
[12/47] Linking CXX executable bin\custom-formatter-test.exe
FAILED: bin/custom-formatter-test.exe
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=test\CMakeFiles\custom-formatter-test.dir --rc=C:\PROGRA~2\WINDOW~4\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WINDOW~4\10\bin\100177~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MIB055~1\2019\BUILDT~1\VC\Tools\MSVC\1420~1.275\bin\Hostx64\x64\link.exe /nologo test\CMakeFiles\custom-formatter-test.dir\custom-formatter-test.cc.obj  /out:bin\custom-formatter-test.exe /implib:test\custom-formatter-test.lib /pdb:bin\custom-formatter-test.pdb /version:0.0  /machine:x64 /INCREMENTAL:NO  /subsystem:console  test\test-main.lib test\gmock.lib fmt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\PROGRA~2\MIB055~1\2019\BUILDT~1\VC\Tools\MSVC\1420~1.275\bin\Hostx64\x64\link.exe /nologo test\CMakeFiles\custom-formatter-test.dir\custom-formatter-test.cc.obj /out:bin\custom-formatter-test.exe /implib:test\custom-formatter-test.lib /pdb:bin\custom-formatter-test.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console test\test-main.lib test\gmock.lib fmt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:bin\custom-formatter-test.exe.manifest" failed (exit code 1120) with the following output:
custom-formatter-test.cc.obj : error LNK2019: unresolved external symbol "bool __cdecl fmt::v5::internal::grisu_format<double,0>(double,class fmt::v5::internal::buffer<char> &,int,unsigned int,int &)" (??$grisu_format@N$0A@@internal@v5@fmt@@YA_NNAEAV?$buffer@D@012@HIAEAH@Z) referenced in function "private: void __cdecl fmt::v5::basic_writer<class fmt::v5::back_insert_range<class fmt::v5::internal::buffer<char> > >::write_double<double>(double,struct fmt::v5::basic_format_specs<char> const &)" (??$write_double@N@?$basic_writer@V?$back_insert_range@V?$buffer@D@internal@v5@fmt@@@v5@fmt@@@v5@fmt@@AEAAXNAEBU?$basic_format_specs@D@12@@Z)
bin\custom-formatter-test.exe : fatal error LNK1120: 1 unresolved externals
[13/47] Building CXX object test\CMakeFiles\format-test.dir\format-test.cc.obj
ninja: build stopped: subcommand failed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, you are right, it should be exported. However FMT_API is already on the declaration, so it shouldn't be needed here:

FMT_API bool grisu_format(Double, buffer<char>&, int, unsigned, int&);
. I wonder why MSVC is complaining.

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway, if it fixes the problem, it's fine to keep FMT_API here but please remove FMT_FUNC then.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've also removed FMT_API from the corresponding declaration in format.h

template <typename Double, FMT_ENABLE_IF(sizeof(Double) == sizeof(uint64_t))>
FMT_API bool grisu_format(Double, buffer<char>&, int, unsigned, int&);

Now it becomes

template <typename Double, FMT_ENABLE_IF(sizeof(Double) == sizeof(uint64_t))>
bool grisu_format(Double, buffer<char>&, int, unsigned, int&);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I didn't refresh this page. Now I'm looking at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In format.h, it's been rolled back to

template <typename Double, FMT_ENABLE_IF(sizeof(Double) == sizeof(uint64_t))>
FMT_API bool grisu_format(Double, buffer<char>&, int, unsigned, int&);

In format-inl.h, remove FMT_FUNC and add FMT_API

template <typename Double, typename std::enable_if<
                               sizeof(Double) == sizeof(uint64_t), int>::type>
FMT_API bool grisu_format(Double value, buffer<char>& buf, int precision,
                           unsigned options, int& exp) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In DLL mode, format-test.cc refers to

internal::count_digits<4,struct fmt::v5::internal::uintptr::uintptr_t>(struct fmt::v5::internal::uintptr::uintptr_t)

The linker can not find symbol :

C:\Users\User\AppData\Roaming\fmt>ninja -j 2
[3/47] Linking CXX shared library bin\fmt.dll
   Creating library fmt.lib and object fmt.exp
[15/47] Linking CXX executable bin\format-test.exe
FAILED: bin/format-test.exe
cmd.exe /C "cd . && "C:\Program Files\CMake\bin\cmake.exe" -E vs_link_exe --intdir=test\CMakeFiles\format-test.dir --rc=C:\PROGRA~2\WINDOW~4\10\bin\100177~1.0\x64\rc.exe --mt=C:\PROGRA~2\WINDOW~4\10\bin\100177~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MIB055~1\2019\BUILDT~1\VC\Tools\MSVC\1420~1.275\bin\Hostx64\x64\link.exe /nologo test\CMakeFiles\format-test.dir\format-test.cc.obj  /out:bin\format-test.exe /implib:test\format-test.lib /pdb:bin\format-test.pdb /version:0.0  /machine:x64 /INCREMENTAL:NO  /subsystem:console  test\test-main.lib test\gmock.lib fmt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
LINK: command "C:\PROGRA~2\MIB055~1\2019\BUILDT~1\VC\Tools\MSVC\1420~1.275\bin\Hostx64\x64\link.exe /nologo test\CMakeFiles\format-test.dir\format-test.cc.obj /out:bin\format-test.exe /implib:test\format-test.lib /pdb:bin\format-test.pdb /version:0.0 /machine:x64 /INCREMENTAL:NO /subsystem:console test\test-main.lib test\gmock.lib fmt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:bin\format-test.exe.manifest" failed (exit code 1120) with the following output:
format-test.cc.obj : error LNK2019: unresolved external symbol "int __cdecl fmt::v5::internal::count_digits<4,struct fmt::v5::internal::uintptr::uintptr_t>(struct fmt::v5::internal::uintptr::uintptr_t)" (??$count_digits@$03Uuintptr_t@uintptr@internal@v5@fmt@@@internal@v5@fmt@@YAHUuintptr_t@uintptr@012@@Z) referenced in function "public: void __cdecl fmt::v5::basic_writer<class fmt::v5::back_insert_range<class fmt::v5::internal::buffer<char> > >::write_pointer<struct fmt::v5::internal::uintptr::uintptr_t>(struct fmt::v5::internal::uintptr::uintptr_t,struct fmt::v5::align_spec const *)" (??$write_pointer@Uuintptr_t@uintptr@internal@v5@fmt@@@?$basic_writer@V?$back_insert_range@V?$buffer@D@internal@v5@fmt@@@v5@fmt@@@v5@fmt@@QEAAXUuintptr_t@uintptr@internal@12@PEBUalign_spec@12@@Z)
bin\format-test.exe : fatal error LNK1120: 1 unresolved externals
[16/47] Building CXX object test\CMakeFiles\assert-test.dir\assert-test.cc.obj
ninja: build stopped: subcommand failed.

In format-test.cc , if I comment out

TEST(WriterTest, WriteUIntPtr) {
  memory_buffer buf;
  fmt::writer writer(buf);
  writer.write_pointer(fmt::internal::bit_cast<fmt::internal::uintptr_t>(
                           reinterpret_cast<void*>(0xface)),
                       FMT_NULL);
  EXPECT_EQ("0xface", to_string(buf));
}

All test are passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, it's already been fixed. I didn't see. Thank you.

unsigned options, int& exp) {
FMT_ASSERT(value >= 0, "value is negative");
bool fixed = (options & grisu_options::fixed) != 0;
Expand Down
9 changes: 8 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

# 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 ()
endif ()

# GTest doesn't detect <tuple> with clang.
Expand Down
17 changes: 12 additions & 5 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2491,18 +2491,25 @@ 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
// 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 fmt::char8_t* data = s.data();
const char8_t* data = s.data();
EXPECT_EQ(data[0], 'a');
EXPECT_EQ(data[1], 'b');
}

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');
Expand All @@ -2513,7 +2520,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);
Expand All @@ -2533,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>::char_type c;
FMT_MAYBE_UNUSED char_traits<char>::char_type c;
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest just doing

(void)c;

and removing the FMT_MAYBE_UNUSED macro because it is not very portable (requires C++17).

#if __cplusplus >= 201103L
std::string s;
begin(s);
FMT_MAYBE_UNUSED auto lval = begin(s);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

#endif
}
7 changes: 7 additions & 0 deletions test/posix-mock-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you post the warnings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

C:\Users\User\AppData\Roaming\fmt>ninja -j 2
[4/47] Linking CXX shared library bin\fmt.dll
   Creating library fmt.lib and object fmt.exp
[35/47] Building CXX object test\CMakeFiles\posix-mock-test.dir\posix-mock-test.cc.obj
C:\Users\User\AppData\Roaming\fmt-master\test\posix-mock-test.cc(469,11): warning: '_create_locale' redeclared without 'dllimport' attribute: 'dllexport' attribute added [-Winconsistent-dllimport]
_locale_t _create_locale(int category, const char* locale) {
          ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\locale.h(105,32): note: previous declaration is here
    _ACRTIMP _locale_t __cdecl _create_locale(
                               ^
C:\Users\User\AppData\Roaming\fmt-master\test\posix-mock-test.cc(473,6): warning: '_free_locale' redeclared without 'dllimport' attribute: 'dllexport' attribute added [-Winconsistent-dllimport]
void _free_locale(_locale_t locale) {
     ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\locale.h(110,27): note: previous declaration is here
    _ACRTIMP void __cdecl _free_locale(
                          ^
C:\Users\User\AppData\Roaming\fmt-master\test\posix-mock-test.cc(477,8): warning: '_strtod_l' redeclared without 'dllimport' attribute: 'dllexport' attribute added [-Winconsistent-dllimport]
double _strtod_l(const char* nptr, char** endptr, _locale_t locale) {
       ^
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17763.0\ucrt\stdlib.h(504,25): note: previous declaration is here
_ACRTIMP double __cdecl _strtod_l(
                        ^
3 warnings generated.

# endif

_locale_t _create_locale(int category, const char* locale) {
return LocaleMock::instance->newlocale(category, locale, 0);
Expand All @@ -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

Expand Down