Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template specialization with type conversion

Tags:

I have found this piece of bogus code (contrived example below):

template <int I, typename T>
struct foo
{
    static int bar()
    {
        return 1;
    }
};

template <std::size_t Index, typename T>
struct foo<Index, T*>
{
    static int bar()
    {
        return 2;
    }
};

Please note that specialization uses different type (by mistake). Surprisingly it compiles without any errors (or warnings) with both GCC 4.8.1 and Clang 3.4. But what is even more strange for GCC line foo<0, int*>::bar() results in 1, but Clang gives 2. What is going on? Is it still considered as a specialization by the standard?