1

I have a project using CMake. The following code builds fine on Apple Clang, MinGW, and Android Cross-Clang but does not build on VS2019:

template<typename Ty> constexpr Ty min(const Ty& _a, const Ty& _b);

Visual Studio produces three errors for the same line:

Error   C2988   unrecognizable template declaration/definition
Error   C2059   syntax error: 'const'
Error   C2059   syntax error: ')'

I feel like it's due to a setting, but Visual Studio is set to use the v142 toolchain and use the latest available C++ standard.

Bart Pelle
  • 747
  • 1
  • 5
  • 18
  • 2
    Visual studio headers (at least *some* versions) have macros defining `min` and `max` (yeah, horrible) , may that be what's tripping you up? – Jesper Juhl Jan 24 '20 at 17:56
  • Can you make a [mre] that reproduces the issue? – NathanOliver Jan 24 '20 at 17:58
  • That was it @JesperJuhl - putting `#undef min` and `#undef max` above it sorted it out. Is there a way to disable VS defining those anyhow? – Bart Pelle Jan 24 '20 at 18:00
  • 2
    Bart:https://stackoverflow.com/questions/11544073/how-do-i-deal-with-the-max-macro-in-windows-h-colliding-with-max-in-std – NathanOliver Jan 24 '20 at 18:02
  • 2
    @BartPelle I Don't know, sorry. I try to stay away from Microsoft products, so I don't know details – Jesper Juhl Jan 24 '20 at 18:03
  • @NathanOliver Thank you! And understandable Jesper - this had me confused as well mainly because of the extremely vague error... Thanks for the pointers! – Bart Pelle Jan 24 '20 at 18:05

0 Answers0