Following code gives expected output on clang 15.0.0 without warning, but not on latest gcc.
When deducting the thrid template parameter std::enable_if_t<std::is_same<T __attribute__((vector_size(8))), TVec>::value>*
, gcc ignores the attributes applied to T
and yields a warning: ignoring attributes applied to dependent type 'T' without an associated declaration
. So the thrid template parameter works as std::enable_if_t<std::is_same<T, TVec>::value>*
, resulting incorrect behavior.


see: https://godbolt.org/z/Kcoe1jh3E
#include <iostream>
#include <type_traits>
template <typename T, typename TVec, std::enable_if_t<std::is_same<T __attribute__((vector_size(8))), TVec>::value>* = nullptr>
void func(){
std::cout << "is 8byte-vector" << std::endl;
}
template <typename T, typename TVec, std::enable_if_t<!std::is_same<T __attribute__((vector_size(8))), TVec>::value>* = nullptr>
void func(){
std::cout << "not 8byte-vector" << std::endl;
}
template <typename t> struct identity { typedef t type; };
int main ()
{
std::cout << std::is_same<float, float __attribute__((vector_size(8)))>::value << std::endl;
func<float, float>(); // expect: NO
func<float, float __attribute__((vector_size(8)))>(); // expect: YES
func<short, short __attribute__((vector_size(8)))>(); // expect: YES
func<short, short __attribute__((vector_size(32)))>(); // expect: NO
}