问题
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];
Is this a GCC bug or voluntary support on the part of clang?
Is there a good work around (besides making s::a a global rather than a static member)?
note: I left out the compiler version as all version of GCC on godbolt do essentially the same thing https://godbolt.org/g/E5s0mi
回答1:
the official documentation of gcc says
Use the section attribute with global variables and not local variables, as shown in the example.
local linkage = wrong? static member variables are local if the class itself is local. and i would say its local through the template declaration.
source
来源:https://stackoverflow.com/questions/42513904/is-attribute-section-something-on-a-static-member-of-a-template-class