c++: C++17 constexpr static data member linkage [PR99901]
authorJason Merrill <jason@redhat.com>
Tue, 6 Apr 2021 05:21:05 +0000 (01:21 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 6 Apr 2021 18:30:02 +0000 (14:30 -0400)
commit8685348075d91945066dea9b564bd42cbc1d22bd
tree56467e80370055dbe45e4b1f27a20924727617c0
parentd48f87d5c1927b1bf2009af3251fe8757e823713
c++: C++17 constexpr static data member linkage [PR99901]

C++17 makes constexpr static data members implicitly inline variables.  In
C++14, a subsequent out-of-class declaration is the definition.  We want to
continue emitting a symbol for such a declaration in C++17 mode, for ABI
compatibility with C++14 code that wants to refer to it.

Normally I'd distinguish in- and out-of-class declarations by looking at
DECL_IN_AGGR_P, but we never set DECL_IN_AGGR_P on inline variables.  I
think that's wrong, but don't want to mess with it so close to release.
Conveniently, we already have a test for in-class declaration earlier in the
function.

gcc/cp/ChangeLog:

PR c++/99901
* decl.c (cp_finish_decl): mark_needed an implicitly inline
static data member with an out-of-class redeclaration.

gcc/testsuite/ChangeLog:

PR c++/99901
* g++.dg/cpp1z/inline-var9.C: New test.
gcc/cp/decl.c
gcc/testsuite/g++.dg/cpp1z/inline-var9.C [new file with mode: 0644]