diff mbox series

[pushed] c++: non-dep structured binding decltype again [PR117107]

Message ID 20241022215637.2120456-1-jason@redhat.com
State New
Headers show
Series [pushed] c++: non-dep structured binding decltype again [PR117107] | expand

Commit Message

Jason Merrill Oct. 22, 2024, 9:56 p.m. UTC
Tested x86_64-pc-linux-gnu, applying to trunk and 14.

-- 8< --

The patch for PR92687 handled the usual case of a decomp variable not being
in the table, but missed the case of there being nothing in the table yet.

	PR c++/117107
	PR c++/92687

gcc/cp/ChangeLog:

	* decl.cc (lookup_decomp_type): Handle null table.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp2a/decomp10.C: New test.
---
 gcc/cp/decl.cc                        |  5 +++--
 gcc/testsuite/g++.dg/cpp2a/decomp10.C | 21 +++++++++++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/decomp10.C


base-commit: f191c8301545658543773ba3d0e6f3f0927529e0
prerequisite-patch-id: fea7085e225c97bf6ef676d9a628cc9abe9ae3cb
diff mbox series

Patch

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 7281818be8f..354b224fd6b 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -9446,8 +9446,9 @@  static GTY((cache)) decl_tree_cache_map *decomp_type_table;
 tree
 lookup_decomp_type (tree v)
 {
-  if (tree *slot = decomp_type_table->get (v))
-    return *slot;
+  if (decomp_type_table)
+    if (tree *slot = decomp_type_table->get (v))
+      return *slot;
   return NULL_TREE;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/decomp10.C b/gcc/testsuite/g++.dg/cpp2a/decomp10.C
new file mode 100644
index 00000000000..8fe425b5d01
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/decomp10.C
@@ -0,0 +1,21 @@ 
+// PR c++/117107
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+template <typename, typename>
+constexpr bool is_same = false;	// { dg-warning "variable template" "" { target c++11_down } }
+template <typename T>
+constexpr bool is_same<T, T> = true; // { dg-warning "variable template" "" { target c++11_down } }
+
+struct tuple {
+  template <unsigned long I>
+  void check_tuple_like() {
+    tuple t;
+    auto [v, r] = t; // { dg-warning "structured bindings" "" { target c++14_down } }
+    (void)[v, r] {   // { dg-warning "captured structured" "" { target c++17_down } }
+        decltype(v) x;
+    };
+  }
+  int a = 0;
+  int &b = a;
+};