I'm having a weird problem where code that is compiled with -Ox
compiles fine, but code that is compiled with -g
fails on link with the following error:
Undefined symbols for architecture x86_64:
"stupid<dummy>::t", referenced from:
stupid<dummy>::operator()(int, int) const in main.o
The code that reproduces this problem:
struct dummy { void operator()(const int a, const int b) const {} ; };
template <typename T>
struct stupid {
constexpr static T t = T(); // create a new one;
stupid() {};
void operator()(int a, int b) const { t(a, b); }
};
int main()
{
const stupid<dummy> a;
a( 1, 2 );
}
It appears that when the code is optimized, the function is inlined and no external function call is asked for, but when the code is NOT optimized, the function is called but isn't there? (I'm not sure why it isn't there...). This happens in g++ 4.7 and 4.8 and clang 3.2.
Any ideas?