public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Simon Martin" <simon@nasilyan.com>
To: "gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: [PATCH] Fix PR c++/111106: missing ; causes internal compiler error
Date: Thu, 30 May 2024 11:31:45 +0000	[thread overview]
Message-ID: <0102018fc9453036-6366d52e-2ec5-4ee3-a7c5-89336bb1b00f-000000@eu-west-1.amazonses.com> (raw)
In-Reply-To: <20240530113143.17575-1-simon@nasilyan.com>

We currently fail upon the following because an assert in dependent_type_p
fails for f's parameter

=== cut here ===
consteval int id (int i) { return i; }
constexpr int
f (auto i) requires requires { id (i) } { return i; }
void g () { f (42); }
=== cut here ===

This patch fixes this by handling synthesized parameters for abbreviated
function templates in that assert.

Successfully tested on x86_64-pc-linux-gnu.

	PR c++/111106

gcc/cp/ChangeLog:

	* pt.cc (dependent_type_p): Relax assert to handle synthesized template
	parameters when !processing_template_decl.

gcc/testsuite/ChangeLog:

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

---
 gcc/cp/pt.cc                             |  6 +++++-
 gcc/testsuite/g++.dg/cpp2a/consteval37.C | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/consteval37.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index dfce1b3c359..a50d5cfd5a2 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -28019,7 +28019,11 @@ dependent_type_p (tree type)
       /* If we are not processing a template, then nobody should be
 	 providing us with a dependent type.  */
       gcc_assert (type);
-      gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto (type));
+      gcc_assert (TREE_CODE (type) != TEMPLATE_TYPE_PARM || is_auto (type)
+		  || (/* Synthesized template parameter */
+		      DECL_TEMPLATE_PARM_P (TEMPLATE_TYPE_DECL (type)) &&
+		      (DECL_IMPLICIT_TEMPLATE_PARM_P
+		       (TEMPLATE_TYPE_DECL (type)))));
       return false;
     }
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval37.C b/gcc/testsuite/g++.dg/cpp2a/consteval37.C
new file mode 100644
index 00000000000..ea2641fc204
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval37.C
@@ -0,0 +1,19 @@
+// PR c++/111106
+// { dg-do compile { target c++20 } }
+
+consteval int id (int i) { return i; }
+
+constexpr int f (auto i) // { dg-line line_1 }
+  requires requires { id (i) } // { dg-error "expected|invalid use" }
+{
+  return i;
+}
+
+void g () {
+  f (42); // { dg-error "parameter 1" }
+}
+
+// { dg-error "constraints on a non-templated" {} { target *-*-* } line_1 }
+// { dg-error "has incomplete type" {} { target *-*-* } line_1 }
+// { dg-error "invalid type for" {} { target *-*-* } line_1 }
+// { dg-note "declared here" {} { target *-*-* } line_1 }
-- 
2.44.0



       reply	other threads:[~2024-05-30 11:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240530113143.17575-1-simon@nasilyan.com>
2024-05-30 11:31 ` Simon Martin [this message]
2024-05-31 20:45   ` Jason Merrill
     [not found]     ` <B494ADFA-90B2-47BA-A57A-2FD29334E4A0@nasilyan.com>
2024-06-04  9:47       ` Simon Martin
2024-06-04 14:18         ` 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=0102018fc9453036-6366d52e-2ec5-4ee3-a7c5-89336bb1b00f-000000@eu-west-1.amazonses.com \
    --to=simon@nasilyan.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).