Take the following piece of code:
#include <type_traits>
#include <iostream>
template <class T>
void print(T &&t){
std::cout << t << std::endl;
}
template<class T, T val>
struct Foo{
static constexpr T value = val;
};
int main(){
print(Foo<int, 123>::value);
}
It refuses to compile under Clang 3.3 and GCC 4.8.1 ("undefined reference to Foo<int, 123>::value")
, which puzzles me because Foo
does exactly the same as std::integral_constant
, and the same code runs fine with integral_constant
. It also fails with plain lvalue reference in the print function. Any explanation regarding this behaviour?
The issue is also present with this quite minimal example:
template<class T>
struct Bar{
static const bool value = true;
};