Template aliases and attributes

Alexander Monakov amonakov@ispras.ru
Fri Nov 29 15:44:00 GMT 2019


On Fri, 29 Nov 2019, Martin Reinecke wrote:

> Hi,
> 
> g++ is unhappy about the statement:
> 
> template<typename T, int len> using vtype = T __attribute__
> ((vector_size (len*sizeof(T))));
> 
> and reports:
> 
> vectest.cc:1:91: warning: ignoring attributes applied to dependent type
> ‘T’ without an associated declaration [-Wattributes]
>     1 |  using vtype = T __attribute__ ((vector_size (len*sizeof(T))));
>       |                                                              ^
> 
> clang++ on the other hand seems to be OK with this.
> 
> Is there some subtlety I'm missing?
> If so, is there analternative way to express what I have in mind?

gcc expects the attribute on the type being declared, not the base type,
so you need to place the attribute on vtype:

template<typename T, int len>
using vtype __attribute__ ((vector_size (len*sizeof(T)))) = T;

This matches how [[attributes]] are meant to be placed in C++11 alias templates.

Alexander


More information about the Gcc-help mailing list