[Bug c++/82443] New: Would like a way to control emission of vague/weak symbol for inline variables
thiago at kde dot org
gcc-bugzilla@gcc.gnu.org
Thu Oct 5 22:10:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82443
Bug ID: 82443
Summary: Would like a way to control emission of vague/weak
symbol for inline variables
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: thiago at kde dot org
Target Milestone: ---
C++17 introduced inline variables and made all static constexpr members be
implicitly inline. With C++14, this code:
=== header.h ===
struct S
{
static constexpr int i = 42;
};
=== tu1.cpp ===
#include <header.h>
constexpr int S::i;
=== tu2.cpp ===
#include <header.h>
const void *f() { return &S::i; }
======
Clang 5 and GCC 7.2, when compiled with -std=c++14, emit the S::i symbol in
tu1.o and it's not weak. There's no S::i symbol emitted in tu2.o.
When compiled with -std=c++17, GCC 7 does not emit the symbol in tu1.o. Clang 5
does. Both compilers emit a weak symbol in tu2.o.
ICC 17 with -std=c++14 emits nothing in tu1.o and emits a weak S::i in tu2.o.
This inconsistency is fragile.
Now add -fvisibility=hidden -fvisibility-inlines-hidden: I'd like a way to make
sure that he inline variable is emitted only in my .cpp file. Everywhere else
that needs to take the address will not emit a copy and will get it from my
.so.
More information about the Gcc-bugs
mailing list