aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2019-10-22 15:21:34 +0000
committerMarek Polacek <polacek@redhat.com>2019-10-22 15:21:34 +0000
commit40f7e4967f98122032cfd074ea49214294855782 (patch)
tree1fe40d2e8c7a2c4dc092cabe57beece6b042462f
parent095d6364195e0f31639b27b542ee2e7200ed118d (diff)
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. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/gcc-9-branch@277294 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/typeck.c6
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/decomp50.C51
3 files changed, 64 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6b9f0930871..4071b72694b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,12 @@
+2019-10-22 Marek Polacek <polacek@redhat.com>
+
+ Backported from mainline
+ 2019-10-21 Marek Polacek <polacek@redhat.com>
+
+ 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 <jakub@redhat.com>
Backported from mainline
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index c815bf3368c..2169f8c4efd 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 00000000000..5400a826948
--- /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 <typename> struct B;
+template <typename _Tp> struct B<_Tp *> { typedef _Tp& reference; };
+struct C {
+ template <typename _Up> using rebind = _Up *;
+};
+template <typename _Iterator, typename> class D {
+public:
+ typename B<_Iterator>::reference operator*();
+ void operator++();
+};
+
+template <typename _Iterator, typename _Container>
+bool operator!=(D<_Iterator, _Container>, D<_Iterator, _Container>);
+template <typename _Tp> class F {
+public:
+ typedef _Tp value_type;
+};
+
+template <typename _Alloc> struct G {
+ template <typename _Tp> struct H { using type = C::rebind<_Tp>; };
+ using const_pointer = typename H<typename _Alloc::value_type>::type;
+};
+template <typename _Tp, typename _Alloc = F<_Tp>> class I {
+ typedef D<typename G<_Alloc>::const_pointer, int> const_iterator;
+
+public:
+ const_iterator begin();
+ const_iterator end();
+};
+
+struct A {
+ struct J {
+ int name;
+ int value;
+ };
+ I<J> members;
+ template <typename Key> const int *find(Key) {
+ for (const auto &[name, value] : members)
+ // See <https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01107.html>
+ // for why we don't warn here.
+ return &value; // { dg-bogus "address of local variable" }
+ return nullptr;
+ }
+};
+int main() {
+ A a;
+ a.find("");
+}