GCC bug: ignoring attributes applied to dependent type ‘T’ without an associated declaration

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.

gcc shows warning and gives incorrect answer
clang works correctly

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
}

你也许会喜欢...

发表回复

您的电子邮箱地址不会被公开。