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

痞子三分冷 提交于 2021-01-29 05:59:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!