]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr.
authormpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 21 Oct 2019 18:22:41 +0000 (18:22 +0000)
committermpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 21 Oct 2019 18:22:41 +0000 (18:22 +0000)
* typeck.c (maybe_warn_about_returning_address_of_local): Avoid
recursing on null initializer and return false instead.

* g++.dg/cpp1z/decomp50.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@277264 138bc75d-0d04-0410-961f-82ee72b054a4

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

index 30accc5941759cb99062009836e1f5d2376abaef..29c6bbd3230b763df32e9cfffabf3442c157279e 100644 (file)
@@ -1,3 +1,9 @@
+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-17  JeanHeyd Meneide  <phdofthehouse@gmail.com>
 
        Implement p1301 [[nodiscard("should have a reason")]] + p1771 DR
index 83604f546fc800119d39b68d08fc177867930890..627dfc2a4fc9068ee4c3ce07d1c6907f32a7b45f 100644 (file)
@@ -9355,8 +9355,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;
index 0259236e41692fd3367d0b44dc0a8ac342636a3d..7365a393a7dd2569d8c934ab78976a246d08ddde 100644 (file)
@@ -1,3 +1,8 @@
+2019-10-21  Marek Polacek  <polacek@redhat.com>
+
+       PR c++/92106 - ICE with structured bindings and -Wreturn-local-addr.
+       * g++.dg/cpp1z/decomp50.C: New test.
+
 2019-10-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/92162
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("");
+}