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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |mpolacek at gcc dot gnu.org,
                   |                            |ppalka at gcc dot gnu.org

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, what happens is that during the implicit instantiation we first set
TREE_READONLY
on the just created decl:
#0  c_apply_type_quals_to_decl (type_quals=1, decl=<var_decl 0x7fffea2f6120 d>)
at ../../gcc/c-family/c-common.cc:3851
#1  0x000000000089a73a in cp_apply_type_quals_to_decl (type_quals=1,
decl=<var_decl 0x7fffea2f6120 d>) at ../../gcc/cp/typeck.cc:11747
#2  0x000000000078d061 in tsubst_decl (t=<var_decl 0x7fffea2f6000 d>,
args=<tree_vec 0x7fffea2d1ec0>, complain=3, use_spec_table=false) at
../../gcc/cp/pt.cc:15609
#3  0x00000000007b0faf in instantiate_template (tmpl=<template_decl
0x7ffff7ffa400 d>, orig_args=<tree_vec 0x7fffea2d1ec0>, complain=3) at
../../gcc/cp/pt.cc:22100
#4  0x000000000076dc12 in finish_template_variable (var=<template_id_expr
0x7fffea2f5348>, complain=3) at ../../gcc/cp/pt.cc:10521
then clear it because it has a non-const initializer:
#0  cp_finish_decl (decl=<var_decl 0x7fffea2f6120 d>, init=<init_expr
0x7fffea2f53e8>, init_const_expr_p=false, asmspec_tree=<tree 0x0>, flags=4,
decomp=0x0)
    at ../../gcc/cp/decl.cc:8945
#1  0x00000000007c64f5 in instantiate_body (pattern=<template_decl
0x7ffff7ffa400 d>, args=<tree_vec 0x7fffea2d1ec0>, d=<var_decl 0x7fffea2f6120
d>, nested_p=false)
    at ../../gcc/cp/pt.cc:27006
#2  0x00000000007c838f in instantiate_decl (d=<var_decl 0x7fffea2f6120 d>,
defer_ok=false, expl_inst_class_mem_p=false) at ../../gcc/cp/pt.cc:27323
#3  0x00000000005a1145 in mark_used (decl=<var_decl 0x7fffea2f6120 d>,
complain=3) at ../../gcc/cp/decl2.cc:6008
but then mark it TREE_READONLY again in
#0  c_apply_type_quals_to_decl (type_quals=1, decl=<var_decl 0x7fffea2f6120 d>)
at ../../gcc/c-family/c-common.cc:3851
#1  0x000000000089a73a in cp_apply_type_quals_to_decl (type_quals=1,
decl=<var_decl 0x7fffea2f6120 d>) at ../../gcc/cp/typeck.cc:11747
#2  0x0000000000566b7c in grokdeclarator (declarator=0x3ebfa00,
declspecs=0x7fffffffd9e0, decl_context=NORMAL, initialized=0,
attrlist=0x7fffffffda50) at ../../gcc/cp/decl.cc:15267
#3  0x00000000006dc206 in cp_parser_explicit_instantiation
(parser=0x7fffea2dea80) at ../../gcc/cp/parser.cc:19864

Perhaps that
    /* Record constancy and volatility on the DECL itself .  There's
       no need to do this when processing a template; we'll do this
       for the instantiated declaration based on the type of DECL.  */
    if (!processing_template_decl)
      cp_apply_type_quals_to_decl (type_quals, decl);
at the end of grokdeclarator needs some further guarding, not do it if it has
been already implicitly instantiated or something similar.
Because I'm afraid by that point I'm afraid information that the var needs to
be runtime initialized isn't present on the VAR_DECL anymore (except in cleared
TREE_READONLY).

Reply via email to