From: Marek Polacek Date: Tue, 22 Oct 2019 15:21:34 +0000 (+0000) Subject: PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr. X-Git-Tag: releases/gcc-9.3.0~507 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d986a59558608834f3259da4bc5f64a868f89774;p=thirdparty%2Fgcc.git PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr. * typeck.c (maybe_warn_about_returning_address_of_local): Avoid recursing on null initializer and return false instead. From-SVN: r277294 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6b9f09308716..4071b72694bd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2019-10-22 Marek Polacek + + Backported from mainline + 2019-10-21 Marek Polacek + + PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr. + * typeck.c (maybe_warn_about_returning_address_of_local): Avoid + recursing on null initializer and return false instead. + 2019-10-21 Jakub Jelinek Backported from mainline diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index c815bf3368cd..2169f8c4efd9 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -9292,8 +9292,10 @@ maybe_warn_about_returning_address_of_local (tree retval) 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); + if (tree init = DECL_INITIAL (base)) + return maybe_warn_about_returning_address_of_local (init); + else + return false; } } bool w = false; diff --git a/gcc/testsuite/g++.dg/cpp1z/decomp50.C b/gcc/testsuite/g++.dg/cpp1z/decomp50.C new file mode 100644 index 000000000000..5400a8269481 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/decomp50.C @@ -0,0 +1,51 @@ +// PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr. +// { dg-do compile { target c++17 } } + +template struct B; +template struct B<_Tp *> { typedef _Tp& reference; }; +struct C { + template using rebind = _Up *; +}; +template class D { +public: + typename B<_Iterator>::reference operator*(); + void operator++(); +}; + +template +bool operator!=(D<_Iterator, _Container>, D<_Iterator, _Container>); +template class F { +public: + typedef _Tp value_type; +}; + +template struct G { + template struct H { using type = C::rebind<_Tp>; }; + using const_pointer = typename H::type; +}; +template > class I { + typedef D::const_pointer, int> const_iterator; + +public: + const_iterator begin(); + const_iterator end(); +}; + +struct A { + struct J { + int name; + int value; + }; + I members; + template const int *find(Key) { + for (const auto &[name, value] : members) + // See + // for why we don't warn here. + return &value; // { dg-bogus "address of local variable" } + return nullptr; + } +}; +int main() { + A a; + a.find(""); +}