[cfe-dev] type traits for vector types

Douglas Gregor dgregor at apple.com
Tue May 11 18:43:51 PDT 2010


On May 11, 2010, at 4:42 PM, Jochen Wilhelmy wrote:

> Hi!
> 
> I'd like to find out info about vectors at compile time.
> 
> For example I have these vector traits:
> template <typename T>
> struct VectorTraits {
>    enum {
>        VECTOR = 0
>    };
> };
> 
> template <>
> struct VectorTraits<float __attribute__((ext_vector_type(2)))> {
>    enum {
>        VECTOR = 2
>    };
> };
> 
> template <>
> struct VectorTraits<float> {
>    enum {
>        VECTOR = 1
>    };
> };
> 
> 
> This fails with the following error:
> error: redefinition of
>      'VectorTraits<float>'
> struct VectorTraits<float>
>        ^~~~~~~~~~~~~~~~~~~

> It seems clang can not specialize by vector type. But when I omit the 
> vector specialization
> the result for a vector type (i.e. VectorTraits<float2>::VECTOR) is 0.
> The vector type does not count as its basic type at instantiation time.
> Therefore this is a bug.

The template argument deduction and checking rules have no understanding of vector types (or extended vector types). You'll need to extend that for templates and vector types to work well together.

  - Doug



More information about the cfe-dev mailing list