]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: follow DR 2386 and update implementation of get_tuple_size [PR110216]
authorgnaggnoyil <gnaggnoyil@gmail.com>
Sat, 12 Aug 2023 08:16:52 +0000 (16:16 +0800)
committerJason Merrill <jason@redhat.com>
Mon, 14 Aug 2023 17:34:42 +0000 (13:34 -0400)
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.

(jason) Accepting pseudonym sign-off because a change this small is not
legally significant for copyright.

DR 2386
PR c++/110216

gcc/cp/ChangeLog:

* decl.cc (get_tuple_size): Update implementation for DR 2386.

gcc/testsuite/ChangeLog:

* g++.dg/cpp1z/decomp10.C: Update expected error for DR 2386.
* g++.dg/cpp1z/pr110216.C: New test.

Signed-off-by: gnaggnoyil <gnaggnoyil@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp1z/decomp10.C
gcc/testsuite/g++.dg/cpp1z/pr110216.C [new file with mode: 0644]

index 126c5818090935468a7f31b9cf69a9f1f20f23d5..62c34bf9abe819a10bc21d96c0c8c247784ae03e 100644 (file)
@@ -8932,10 +8932,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)
index f0723f8d85f2f909ff9fb7977f57aa0091659835..af83a79e781219734b178bf3c1853c6225f2494d 100644 (file)
@@ -7,7 +7,7 @@ namespace std {
 
 struct A1 { int i,j; } a1;
 template<> struct std::tuple_size<A1> {  };
-void f1() { auto [ x ] = a1; } // { dg-error "is not an integral constant expression" }
+void f1() { auto [ x ] = a1; } // { dg-error "only 1 name provided" }
 
 struct A2 { int i,j; } a2;
 template<> struct std::tuple_size<A2> { enum { value = 5 }; };
diff --git a/gcc/testsuite/g++.dg/cpp1z/pr110216.C b/gcc/testsuite/g++.dg/cpp1z/pr110216.C
new file mode 100644 (file)
index 0000000..be4fd5f
--- /dev/null
@@ -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 ()
+{
+}