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

Windows build fails due to Windows.h min/max macro #1772

Closed
efiturri opened this issue Oct 15, 2019 · 0 comments
Closed

Windows build fails due to Windows.h min/max macro #1772

efiturri opened this issue Oct 15, 2019 · 0 comments

Comments

@efiturri
Copy link

Bug description
Latest release of catch2 doesn't build on windows if Windows.h was at any point included before it and NOMINMAX is not defined. Line causes 4487 multiple errors and causes any program including it to fail to build.

C:\Git-Projects\apex\build-windows-Debug\catch2\src\git_catch\single_include\catch2\catch.hpp(4487): warning C4003: not enough arguments for function-like macro invocation 'min'
C:\Git-Projects\apex\build-windows-Debug\catch2\src\git_catch\single_include\catch2\catch.hpp(4487): error C2059: syntax error: ')'
C:\Git-Projects\apex\build-windows-Debug\catch2\src\git_catch\single_include\catch2\catch.hpp(4487): error C2334: unexpected token(s) preceding ':'; skipping apparent function body

Expected behavior
Should compile regardless of the macro being set

Reproduction steps
Just create a CPP that includes Windows.h before catch.hpp and windows will fail to compile if you don't have the NOMINMAX macro defined

Platform information:

  • OS: Windows 10
  • Compiler+version: Visual Studio v16.0.4
  • Catch version: v2.10.0

Additional context
I simply added -DNOMINMAX to my cmake compile scripts to get it to build. Probably something I should have done before.
Fix is easy though, if I change line 4487 in single_include/catch.hpp:

        static constexpr result_type min() {
            return 0;
        }
        static constexpr result_type max() {
            return static_cast<result_type>(-1);
        }

to

        static constexpr result_type (min)() {
            return 0;
        }
        static constexpr result_type (max)() {
            return static_cast<result_type>(-1);
        }

It compiles without issues even without NOMINMAX

amitherman95 pushed a commit to amitherman95/Catch2 that referenced this issue Oct 18, 2019
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

No branches or pull requests

1 participant