c++: follow DR 2386 and update implementation of get_tuple_size [PR110216]

Message ID 20230806181535.71101-1-gnaggnoyil@gmail.com
State Unresolved
Headers
Series c++: follow DR 2386 and update implementation of get_tuple_size [PR110216] |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

gnaggnoyil Aug. 6, 2023, 6:15 p.m. UTC
  DR 2386 updated the tuple_size requirements for structured binding and
it now requires tuple_size to be considered only if
std::tuple_size<TYPE> names a complete class type with member value. GCC
before this patch does not follow the updated requrements, and this
patch is intended to implement it.

	DR 2386
	PR c++/110216

gcc/cp/ChangeLog:

	* decl.cc (get_tuple_size): Update implemetation to follow DR 2386.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Yonggang Li <gnaggnoyil@gmail.com>
---
 gcc/cp/decl.cc                        |  6 +++++-
 gcc/testsuite/g++.dg/cpp1z/pr110216.C | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/pr110216.C
  

Comments

Jason Merrill Aug. 8, 2023, 7:38 p.m. UTC | #1
On 8/6/23 14:15, gnaggnoyil wrote:
> DR 2386 updated the tuple_size requirements for structured binding and
> it now requires tuple_size to be considered only if
> std::tuple_size<TYPE> names a complete class type with member value. GCC
> before this patch does not follow the updated requrements, and this
> patch is intended to implement it.
> 
> 	DR 2386
> 	PR c++/110216
> 
> gcc/cp/ChangeLog:
> 
> 	* decl.cc (get_tuple_size): Update implemetation to follow DR 2386.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/cpp1z/pr110216.C: New test.

Thanks!  Unfortunately, I see that this patch causes a testsuite failure 
in cpp1z/decomp10.C.  This seems to be an intended change of behavior, 
but please also update that testcase, and remember to run the testsuite 
before submitting a patch.

Jason
  

Patch

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 792ab330dd0..923b81a33b0 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8940,10 +8940,14 @@  get_tuple_size (tree type)
 				     /*context*/std_node,
 				     /*entering_scope*/false, tf_none);
   inst = complete_type (inst);
-  if (inst == error_mark_node || !COMPLETE_TYPE_P (inst))
+  if (inst == error_mark_node
+      || !COMPLETE_TYPE_P (inst)
+      || !CLASS_TYPE_P (type))
     return NULL_TREE;
   tree val = lookup_qualified_name (inst, value_identifier,
 				    LOOK_want::NORMAL, /*complain*/false);
+  if (val == error_mark_node)
+    return NULL_TREE;
   if (VAR_P (val) || TREE_CODE (val) == CONST_DECL)
     val = maybe_constant_value (val);
   if (TREE_CODE (val) == INTEGER_CST)
diff --git a/gcc/testsuite/g++.dg/cpp1z/pr110216.C b/gcc/testsuite/g++.dg/cpp1z/pr110216.C
new file mode 100644
index 00000000000..be4fd5f7053
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/pr110216.C
@@ -0,0 +1,21 @@ 
+// DR 2386
+// PR c++/110216
+// { dg-do compile { target c++17 } }
+
+
+namespace std{
+  template <typename T> struct tuple_size;
+}
+
+struct A {
+  int x = 0;
+};
+
+template <> struct std::tuple_size <::A> {};
+
+auto [x] = A{};
+
+int
+main ()
+{
+}