serge-sans-paille / frozen

a header-only, constexpr alternative to gperf for C++14 users
Apache License 2.0
1.27k stars 103 forks source link

[Windows][VS][MSVC] Compilation failed - min / max macros #127

Closed Armillus closed 3 years ago

Armillus commented 3 years ago

Hello,

I have a problem with frozen that I already met with other libraries. In my program, on Windows 10, with Visual Studio 16.10 and MSVC, I cannot compile because of the following errors:

1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(134,76): warning C4003: not enough arguments for function-like macro invocation 'max'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(134,76): error C2589: '(': illegal token on right side of '::'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(134): error C2062: type 'unknown-type' unexpected
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(134,41): error C2789: 'frozen::bits::seed_or_index::MINUS_ONE': an object of const-qualified type must be initialized
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(134): message : see declaration of 'frozen::bits::seed_or_index::MINUS_ONE'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(134,76): error C2059: syntax error: ')'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(135,42): error C2131: expression did not evaluate to a constant
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(135,44): message : failure was caused by a read of an uninitialized symbol
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(135,44): message : see usage of 'MINUS_ONE'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\bits\pmh.h(186,68): warning C4003: not enough arguments for function-like macro invocation 'max'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(65,32): warning C4003: not enough arguments for function-like macro invocation 'min'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(66,32): warning C4003: not enough arguments for function-like macro invocation 'max'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(65,32): error C2059: syntax error: ')'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(78): message : see reference to class template instantiation 'frozen::linear_congruential_engine<UIntType,a,c,m>' being compiled
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(65,1): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(78,1): error C2143: syntax error: missing ')' before ';'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(78,1): error C2059: syntax error: ')'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(78,1): error C2238: unexpected token(s) preceding ';'
1>C:\Users\millo\Documents\Programming\vcpkg\installed\x64-windows\include\frozen\random.h(78,1): fatal error C1201: unable to continue after syntax error in class template definition

I previously faced this problem with quill and they fixed it with #define NOMINMAX. Here is the link of the original issue if you're interested: https://github.com/odygrd/quill/issues/94#issuecomment-808887771.

Is it possible to fix this issue in frozen too?

I would be happy to provide more information if needed.

Thank you in advance,

Armillus

gracicot commented 3 years ago

See #115. The win32 headers are broken unless you define NOMINMAX.

The win32 header are not compatible with the C++ standard out of the box.

Armillus commented 3 years ago

Okay, got it.

By defining NOMINMAX it works well on my side, I just wanted to be sure that you are aware of the problem, but obviously I should have searched more carefully in closed issues.

Thank you, and keep going with this great and useful library that frozen is!