[Bug c++/87947] Symbol Does Not Appear in Object File

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Nov 9 01:10:00 GMT 2018


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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to comm+gnu from comment #0)
> The expected behavior is that A::foobar is exposed as a symbol. Note that
> -std=c++17 is required to duplicate this.

Your expectation is wrong. In C++17 the static data member is implicitly
"inline" which means a definition is only emitted when it's odr-used (and the
namespace scope definition is redundant, and deprecated).

GCC 6.x does not implement the C++17 rule, so still emits the symbol.

If you need to ensure a definition is emitted in a given object file either
compile it as C++14, or mark it as used:

[[gnu::used]] constexpr int A::foobar;


More information about the Gcc-bugs mailing list