是否允许在模板类的静态成员上__attribute__((节(".something")))?

is __attribute__((section(".something"))) on a static member of a template class allowed?

本文关键字:attribute something 静态成员 是否      更新时间:2023-10-16

在以下示例中,clang正确地将相应的变量正确地放入了.aaa'和'.ggg'中。GCC在" .GGG"上工作,但不使用'.AAA'(类模板的静态成员变量)。

template<int I>
struct s{
    __attribute__((section(".aaa"))) static  int a[100];
};
__attribute__((section(".ggg"))) int  b[100]; 
template<int I>
__attribute__((section(".aaa"))) int s<I>::a[100];

这是Clang的GCC错误还是自愿支持?

是否有很好的工作(除了使S ::一个全球而不是静态成员制作)?

注意:我省略了编译器版本,因为Godbolt上的所有GCC的所有版本基本上是同一件事https://godbolt.org/g/e5s0mi

gcc的正式文档说

如示例所示,使用带有全局变量而不是本地变量的部分属性。

本地链接=错误?如果类本身是本地,则静态成员变量是本地的。我会通过模板声明说其本地。