Hi, Thanks for reaching out and taking a stab at this bug!
On Sat, 15 Nov 2025, mkryss via Gcc wrote: > > Hello, > I recently stumbled upon the ICE described in bug 122658 in my code and have > been trying to fix with no success (mostly because I have no gcc development > experience). > > The ICE seems to happen when tsubst_expr is called with a TARGET_EXPR tree, > that's not handled by the switch so it goes into the default case and ICEs. Yep, TARGET_EXPR shouldn't appear inside a template because TARGET_EXPR is a way of representing temporary objects, something that we don't bother worrying about when producing an AST for a template definition. So tsubst_expr, which expects to see only templated trees, rightfully crashes when it sees a TARGET_EXPR. > > Before 3e3d73ed5e85 that introduced this bug, it seems that this was not > failing because tsubst_expr (at the time tsubst_copy_and_build)'s default > case was calling tsubst_copy that then returned early in case of a null args > tree, but now tsubst_expr just ICEs in case of an unhandled tree code. > > I've been trying to find a proper way to handle this with no success, does > anyone have any tips? Would the right way be to add a switch case for > TARGET_EXPR? Or is there something else I'm missing? The function that's creating a TARGET_EXPR should probably be suppressed when called inside a template, i.e. when processing_template_decl != 0. The easiest way to find this is by creating a location watchpoint in GDB on t.base.code where t is the TARGET_EXPR tree. https://gcc-newbies-guide.readthedocs.io/en/latest/debugging.html#how-do-i-find-where-a-particular-tree-was-created > > Thanks and sorry if there's some trivial fix I've missed.
