https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125753
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
This has been a tricky problem. If the "template for" is in an ordinary
function, there's no problem.
Basically, we create a BLOCK in cp_parser_expansion_statement -> do_poplevel
which contains the SPLICE_SCOPE, because we haven't tsubst_splice_scope'd it
yet. This BLOCK is a subblock of other BLOCKs, coming from
finish_expansion_statement, finish_compound_statement etc. decls_for_scope
recurses on BLOCKs:
/* Output the DIEs to represent all sub-blocks (and the items declared
therein) of this block. */
if (recurse)
for (subblocks = BLOCK_SUBBLOCKS (stmt);
subblocks != NULL;
subblocks = BLOCK_CHAIN (subblocks))
gen_block_die (subblocks, context_die);
And eventually it reaches the BLOCK with the SPLICE_SCOPE in its BLOCK_VARS.
We create such a BLOCK in the ordinary function case as well, but it's never
walked in c_common_finalize_early_debug. I don't know if our cdtor cloning has
something to do with this. It seems clear that a BLOCK with unsubstituted
decls should never reach dwarf2out_decl &co.