public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jason Merrill <jason@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: [PATCH] c++: Implement CWG2635 - Constrained structured bindings
Date: Sat, 12 Nov 2022 12:23:54 +0100	[thread overview]
Message-ID: <Y2+CSlWHeS+aGxVZ@tucnak> (raw)

Hi!

The following patch implements CWG2635.

So far tested on
GXX_TESTSUITE_STDS=98,11,14,17,20,2b make check-g++ RUNTESTFLAGS="dg.exp=decomp*"
ok for trunk if it passes full bootstrap/regtest and it is voted in?

2022-11-12  Jakub Jelinek  <jakub@redhat.com>

	* decl.cc (grokdeclarator): Implement
	CWG2635 - Constrained structured bindings.  Diagnose constrained
	auto type.

	* g++.dg/cpp2a/decomp5.C: New test.

--- gcc/cp/decl.cc.jj	2022-11-11 17:14:33.103869977 +0100
+++ gcc/cp/decl.cc	2022-11-12 12:13:52.217239729 +0100
@@ -12660,7 +12660,8 @@ grokdeclarator (const cp_declarator *dec
 	  gcc_unreachable ();
 	}
       if (TREE_CODE (type) != TEMPLATE_TYPE_PARM
-	  || TYPE_IDENTIFIER (type) != auto_identifier)
+	  || TYPE_IDENTIFIER (type) != auto_identifier
+	  || PLACEHOLDER_TYPE_CONSTRAINTS_INFO (type))
 	{
 	  if (type != error_mark_node)
 	    {
--- gcc/testsuite/g++.dg/cpp2a/decomp5.C.jj	2022-11-12 12:17:21.024392082 +0100
+++ gcc/testsuite/g++.dg/cpp2a/decomp5.C	2022-11-12 12:20:00.700214521 +0100
@@ -0,0 +1,20 @@
+// CWG2635 - Constrained structured bindings 
+// { dg-do compile { target c++20 } }
+
+namespace std {
+  template<typename T> struct tuple_size;
+  template<int, typename> struct tuple_element;
+}
+
+struct A {
+  int i;
+  A(int x) : i(x) {}
+  template <int I> int& get() { return i; }
+};
+
+template<> struct std::tuple_size<A> { static const int value = 2; };
+template<int I> struct std::tuple_element<I,A> { using type = int; };
+
+template<class T> concept C = true;
+C auto [x, y] = A{1}; // { dg-error "structured binding declaration cannot have type 'auto \\\[requires ::C<<placeholder>, >\\\]'" }
+		      // { dg-message "type must be cv-qualified 'auto' or reference to cv-qualified 'auto'" "" { target *-*-* } .-1 }

	Jakub


             reply	other threads:[~2022-11-12 11:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12 11:23 Jakub Jelinek [this message]
2022-11-13 11:50 ` [PATCH] c++, v2: " Jakub Jelinek
2022-11-15 23:22   ` Jason Merrill
2022-11-16 10:17     ` [PATCH] c++, v3: " Jakub Jelinek
2022-11-16 13:12       ` Jason Merrill

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y2+CSlWHeS+aGxVZ@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).