public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v1] c++: follow DR 2386 and update implementation of get_tuple_size [PR110216]
@ 2023-08-12  8:16 gnaggnoyil
  2023-08-14 17:58 ` Jason Merrill
  0 siblings, 1 reply; 2+ messages in thread
From: gnaggnoyil @ 2023-08-12  8:16 UTC (permalink / raw)
  To: gcc-patches; +Cc: jason, nathan, polacek, gnaggnoyil

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/decomp10.C: Update expected error message for DR 2386.
	* g++.dg/cpp1z/pr110216.C: New test.

Signed-off-by: gnaggnoyil <gnaggnoyil@gmail.com>
---

Hi,

As https://gcc.gnu.org/pipermail/gcc-patches/2023-August/626696.html mentioned,
I've updated the corresponding tests. I ran all tests in g++.dg and no
unexpected fail exists now.

 gcc/cp/decl.cc                        |  6 +++++-
 gcc/testsuite/g++.dg/cpp1z/decomp10.C |  2 +-
 gcc/testsuite/g++.dg/cpp1z/pr110216.C | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp1z/pr110216.C

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/decomp10.C b/gcc/testsuite/g++.dg/cpp1z/decomp10.C
index f0723f8d85f..af83a79e781 100644
--- a/gcc/testsuite/g++.dg/cpp1z/decomp10.C
+++ b/gcc/testsuite/g++.dg/cpp1z/decomp10.C
@@ -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
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 ()
+{
+}
-- 
2.41.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v1] c++: follow DR 2386 and update implementation of get_tuple_size [PR110216]
  2023-08-12  8:16 [PATCH v1] c++: follow DR 2386 and update implementation of get_tuple_size [PR110216] gnaggnoyil
@ 2023-08-14 17:58 ` Jason Merrill
  0 siblings, 0 replies; 2+ messages in thread
From: Jason Merrill @ 2023-08-14 17:58 UTC (permalink / raw)
  To: gnaggnoyil, gcc-patches

On 8/12/23 04:16, 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/decomp10.C: Update expected error message for DR 2386.
> 	* g++.dg/cpp1z/pr110216.C: New test.
> 
> Signed-off-by: gnaggnoyil <gnaggnoyil@gmail.com>

Pushed, thanks!

Note that the GCC DCO policy (https://gcc.gnu.org/dco.html) requires 
real names in the sign-off; in this case I've applied the patch anyway 
because it is small enough that it's not legally significant for copyright.

I think if you want to contribute larger patches under this pseudonym, 
you should file a copyright assignment with the FSF, which explicitly 
allows this.  "If a contributor wants the FSF to publish only a 
pseudonym, that is ok. The contributor should say this, and state the 
desired pseudonym, when answering the request- form. The actual legal 
papers will use the real name, but the FSF will publish only the 
pseudonym."[2]

Thanks again,
Jason

[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/Documentation/process?id=d4563201f33a022fc0353033d9dfeb1606a88330
[2] https://www.gnu.org/prep/maintain/maintain.html#Copyright-Papers


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-14 17:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-12  8:16 [PATCH v1] c++: follow DR 2386 and update implementation of get_tuple_size [PR110216] gnaggnoyil
2023-08-14 17:58 ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).