[Bug c++/92106] [8/9/10 Regression] ICE with structured bindings and -Wreturn-local-addr
mpolacek at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Oct 15 16:34:00 GMT 2019
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92106
--- Comment #4 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #3)
> (In reply to Marek Polacek from comment #2)
> > 9351 /* When returning address of a structured binding, if the
> > structured
> > 9352 binding is not a reference, continue normally, if it is a
> > 9353 reference, recurse on the initializer of the structured
> > 9354 binding. */
> > 9355 tree base = DECL_DECOMP_BASE (whats_returned);
> > 9356 if (TYPE_REF_P (TREE_TYPE (base)))
> > 9357 {
> > 9358 tree init = DECL_INITIAL (base);
> > 9359 return maybe_warn_about_returning_address_of_local
> > (init);
> > 9360 }
> >
> > init is null here and cp_fold crashes on that.
>
> I'd add
> && DECL_INITIAL (base)
> to line 9356.
I'm testing the below -- wanted to lose the { }s and avoid using DECL_INITIAL
twice.
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -9353,11 +9353,10 @@ maybe_warn_about_returning_address_of_local (tree
retval)
reference, recurse on the initializer of the structured
binding. */
tree base = DECL_DECOMP_BASE (whats_returned);
- if (TYPE_REF_P (TREE_TYPE (base)))
- {
- tree init = DECL_INITIAL (base);
- return maybe_warn_about_returning_address_of_local (init);
- }
+ tree init;
+ if (TYPE_REF_P (TREE_TYPE (base))
+ && (init = DECL_INITIAL (base)))
+ return maybe_warn_about_returning_address_of_local (init);
}
bool w = false;
auto_diagnostic_group d;
> Maybe it would be better to add return nullptr;
> to find if the range for loop has no iterations.
Added -- it's not relevant to this bug.
More information about the Gcc-bugs
mailing list