]> gcc.gnu.org Git - gcc.git/commit
c++: Fix explicit instantiation of const variable templates after earlier implicit...
authorJakub Jelinek <jakub@redhat.com>
Wed, 28 Feb 2024 22:20:13 +0000 (23:20 +0100)
committerJakub Jelinek <jakub@redhat.com>
Wed, 28 Feb 2024 22:20:13 +0000 (23:20 +0100)
commit29ac92436aa5c702e9e02c206e7590ebd806398e
treea3f10e8430c3ee256c2090f028b6766e17dbf92d
parentbfecc907373addbdd6969e49caea6ff5d3ce1dc7
c++: Fix explicit instantiation of const variable templates after earlier implicit instantation [PR113976]

Already previously instantiated const variable templates had
cp_apply_type_quals_to_decl called when they were instantiated,
but if they need runtime initialization, their TREE_READONLY flag
has been subsequently cleared.
Explicit variable template instantiation calls grokdeclarator which
calls cp_apply_type_quals_to_decl on them again, setting TREE_READONLY
flag again, but nothing clears it afterwards, so we emit such
instantiations into rodata sections and segfault when the dynamic
initialization attempts to initialize them.

The following patch fixes that by not calling cp_apply_type_quals_to_decl
on already instantiated variable declarations.

2024-02-28  Jakub Jelinek  <jakub@redhat.com>
    Patrick Palka  <ppalka@redhat.com>

PR c++/113976
* decl.cc (grokdeclarator): Don't call cp_apply_type_quals_to_decl
on DECL_TEMPLATE_INSTANTIATED VAR_DECLs.

* g++.dg/cpp1y/var-templ87.C: New test.
gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp1y/var-templ87.C [new file with mode: 0644]
This page took 0.058492 seconds and 5 git commands to generate.