I've trimmed down the EXPECT_TRUE
macro from gtest.h.
#include <type_traits>
#include <iostream>
class rai_class {
public:
static bool const value = true;
};
class AssertionResult {
public:
template <typename T>
explicit AssertionResult(
const T& success,
typename std::enable_if<
!std::is_convertible<T, AssertionResult>::value>::type*
= nullptr)
: success_(success) {}
operator bool() const { return success_; }
private:
bool success_;
};
// Test type trait
bool test_rai_hash_implemented()
{
return AssertionResult(rai_class::value);
//return rai_class::value;
}
int main()
{
std::cout << test_rai_hash_implemented() << "\n";
return 0;
}
Without optimisations, it produces the link error "undefined reference to `rai_class::value'".
With -O2 it works ok. Any ideas what's going on?
Thanks.
value
in our code was actually given the same assignment as the enum in this answer: stackoverflow.com/a/257382/1958315. Your answer motivates changing the definition to anenum
, which works.