]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr.
authorMarek Polacek <polacek@redhat.com>
Tue, 22 Oct 2019 15:21:34 +0000 (15:21 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 22 Oct 2019 15:21:34 +0000 (15:21 +0000)
* typeck.c (maybe_warn_about_returning_address_of_local): Avoid
recursing on null initializer and return false instead.

From-SVN: r277294

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/g++.dg/cpp1z/decomp50.C [new file with mode: 0644]

index 6b9f09308716676edea4273a0563340d9ede70c6..4071b72694bd748cca6a761821034fd9428743fc 100644 (file)
@@ -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
index c815bf3368cd12aa073efc090b22e27bf10f723d..2169f8c4efd9408c2fd17b96b0d22fd5b465500f 100644 (file)
@@ -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 (file)
index 0000000..5400a82
--- /dev/null
@@ -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("");
+}