[Bug c++/88061] section attributes of variable templates are ignored

barry.revzin at gmail dot com gcc-bugzilla@gcc.gnu.org
Tue Mar 8 17:31:17 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88061

Barry Revzin <barry.revzin at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |barry.revzin at gmail dot com

--- Comment #5 from Barry Revzin <barry.revzin at gmail dot com> ---
(In reply to Richard Biener from comment #1)
> Some things do not make very much sense for C++...

I disagree. This definitely makes sense for C++ and it is disappointing that it
doesn't work. 

For instance, this works:

[[gnu::used, gnu::section(".my_data")]] inline int data_int;
[[gnu::used, gnu::section(".my_data")]] inline double data_double;

int& get() {
    return data_int;
}

The C++ analogue, necessary for contexts where I may not be able to spell the
type in advance, would be this (or a static data member of a class template,
same thing):

template <typename T>
[[gnu::used, gnu::section(".my_data")]] inline T data{};

int& get() {
    return data<int>;
}

Except the latter puts data<int> into .bss.data<int>, while the former puts it
into .my_data. clang respects the section attribute
(https://godbolt.org/z/7137EbxsW), gcc does not
(https://godbolt.org/z/548YKjhzn).


More information about the Gcc-bugs mailing list