I noticed that static statements in class templates do not start when instances of typedef'ed.
#include <type_traits>
template <typename T>
struct test_assert
{
static_assert( std::is_same< T, int >::value, "should fail" );
};
typedef test_assert< float > t;
This code compiles without errors. If I try to create an instance, the statement fails:
t obj;
Finally, if I replaced the condition with false, the statement fails, even if I do not instantiate the class template:
template <typename T>
struct test_assert
{
static_assert( false, "always fails" );
};
I tried this code on gcc-4.5.1 and gcc-4.7.0. Is this normal behavior? What time should the compiler check for static statements? I suppose a two-phase search is used, but shouldn't typedef trigger the second phase?
source
share