Skip to content

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

@efiturri

Description

@efiturri

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions