问题描述
lang将相应的变量正确地放置在'.aaa'和'.ggg'中.GCC在'.ggg'上工作,但在'.aaa'(类模板的静态成员变量)上不工作.
in the following example clang puts the respective variables in '.aaa' and '.ggg' correctly. GCC works on '.ggg' but not on '.aaa' (the static member variable of the class template).
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];
这是CCC漏洞还是clang的自愿支持?
Is this a GCC bug or voluntary support on the part of clang?
是否有很好的解决方法(除了使s :: a为全局成员,而不是静态成员)?
Is there a good work around (besides making s::a a global rather than a static member)?
注意:我遗漏了编译器版本,因为Godbolt上的所有GCC版本实际上都做同样的事情 https://godbolt.org/g/E5s0mi
note: I left out the compiler version as all version of GCC on godbolt do essentially the same thing https://godbolt.org/g/E5s0mi
推荐答案
gcc的官方文档说
本地链接=错误?如果类本身是本地的,则静态成员变量是本地的.我会通过模板声明说它的本地性.
local linkage = wrong?static member variables are local if the class itself is local. and i would say its local through the template declaration.
这篇关于是否允许在模板类的静态成员上使用__attribute __((section(“.something"))))?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!