I have a linker problem with the code below. It works with the Visual Studio 2015 compiler, but not with Clang/LLVM in Visual Studio. I have tried may different variations (some below), all work fine. It seems to be the specific combination of the static constexpr numeric_limits<double>
and REQUIRE
.
// quicktest.cpp
#include <limits>
#include <iostream>
#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file
#include <catch.hpp>
struct X {
static constexpr double min = std::numeric_limits<double>::min();
static constexpr int min_int = std::numeric_limits<int>::min();
};
SCENARIO("blah")
{
static const double my_min = X::min; // works
std::cout << (5 > X::min) << std::endl; // works
REQUIRE(5 > my_min); // works
REQUIRE(5 > X::min_int); // works (int)
REQUIRE(5 > std::numeric_limits<double>::min()); // works
//REQUIRE(5 > X::min); // lnk2019
}
//int main()
//{
// std::cout << (X::min < 5) << std::endl; // works
// return 0;
//}
The exact error message with the last REQUIRE
commented in is:
Error LNK2019 unresolved external symbol "public: static double const X::min" (?min@X@@2NB) referenced in function "int
void __cdecl anonymous namespace'::
dynamic initializer for 'autoRegistrar11''(void)'::1'::dtor$2" (?dtor$2@?0???__EautoRegistrar11@?A@@YAXXZ@4HA) quicktest ...\quicktest\quicktest.obj 1
Luckily, it is simple to work around, but I was wondering what could be the exact reason for the problem. Actually, I have no idea, whether it is originating in catch or in the compiler or whatever. Any idea anyone?