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

--- Comment #17 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-12 branch has been updated by Jakub Jelinek
<ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:64a7a19112f04a548ebe18ada80b8c2d18997c3e

commit r12-11193-g64a7a19112f04a548ebe18ada80b8c2d18997c3e
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Wed Feb 28 23:20:13 2024 +0100

    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  <ja...@redhat.com>
                Patrick Palka  <ppa...@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.

    (cherry picked from commit 29ac92436aa5c702e9e02c206e7590ebd806398e)

Reply via email to