Should static_assert be triggered using typedef?

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; // error: static assertion failed: "should fail"

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?

+5
source share
1 answer

gcc-4.5.1 gcc-4.7.0. ?

?

. , , .

, , typedef ?

, typedef . :

template <typename T> class unique_ptr;
typedef unique_ptr<int> int_unique_ptr;

, typedef, . , , ( , - ).

+9

All Articles