public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix PR c++/111106: missing ; causes internal compiler error
       [not found] <20240530113143.17575-1-simon@nasilyan.com>
@ 2024-05-30 11:31 ` Simon Martin
  2024-05-31 20:45   ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Martin @ 2024-05-30 11:31 UTC (permalink / raw)
  To: gcc-patches

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



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

* Re: [PATCH] Fix PR c++/111106: missing ; causes internal compiler error
  2024-05-30 11:31 ` [PATCH] Fix PR c++/111106: missing ; causes internal compiler error Simon Martin
@ 2024-05-31 20:45   ` Jason Merrill
       [not found]     ` <B494ADFA-90B2-47BA-A57A-2FD29334E4A0@nasilyan.com>
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2024-05-31 20:45 UTC (permalink / raw)
  To: Simon Martin, gcc-patches

On 5/30/24 07:31, Simon Martin wrote:
> 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.

I don't see why implicit template parameters should be handled 
differently from explicit ones here.

This seems more like an error-recovery issue, and I'd be open to adding 
|| seen_error() to that assert like in various others.

> 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 }

These errors are wrong, so should not be tested for;  only the syntax 
error about the missing semicolon should have a dg-error.  You can use 
dg-excess-errors to cover the rest.

Jason


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

* Re: [PATCH] Fix PR c++/111106: missing ; causes internal compiler error
       [not found]     ` <B494ADFA-90B2-47BA-A57A-2FD29334E4A0@nasilyan.com>
@ 2024-06-04  9:47       ` Simon Martin
  2024-06-04 14:18         ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Martin @ 2024-06-04  9:47 UTC (permalink / raw)
  To: Jason Merrill; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 3338 bytes --]

Hi Jason,

Thanks for the review.

On 31 May 2024, at 22:45, Jason Merrill wrote:

> On 5/30/24 07:31, Simon Martin wrote:
>> 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.
>
> I don't see why implicit template parameters should be handled 
> differently from explicit ones here.
>
> This seems more like an error-recovery issue, and I'd be open to 
> adding || seen_error() to that assert like in various others.
>
Makes sense; this is what the attached updated patch (successfully 
tested on x86_64-pc-linux-gnu) does.

Is it better and OK for trunk?

>> 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 }
>
> These errors are wrong, so should not be tested for;  only the syntax 
> error about the missing semicolon should have a dg-error.  You can use 
> dg-excess-errors to cover the rest.
>
Addressed in the updated patch. Thanks!

> Jason

[-- Attachment #2: 0001-Fix-PR-c-111106-missing-causes-internal-compiler-err.patch --]
[-- Type: text/plain, Size: 2110 bytes --]

From ec9be7818bc9f7c46e9a1fbbb8b0c9ac030fa63d Mon Sep 17 00:00:00 2001
From: Simon Martin <simon@nasilyan.com>
Date: Fri, 24 May 2024 17:00:17 +0200
Subject: [PATCH] Fix PR c++/111106: missing ; causes internal compiler error

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 relaxing the assert to pass during error recovery.

Successfully tested on x86_64-pc-linux-gnu.

	PR c++/111106

gcc/cp/ChangeLog:

	* pt.cc (dependent_type_p): Don't fail assert during error recovery.

gcc/testsuite/ChangeLog:

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

---
 gcc/cp/pt.cc                             |  3 ++-
 gcc/testsuite/g++.dg/cpp2a/consteval37.C | 16 ++++++++++++++++
 2 files changed, 18 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..edb94a000ea 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -28019,7 +28019,8 @@ 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)
+		  || seen_error());
       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..519d83d9bf8
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/consteval37.C
@@ -0,0 +1,16 @@
+// PR c++/111106
+// { dg-do compile { target c++20 } }
+
+consteval int id (int i) { return i; }
+
+constexpr int f (auto i)
+  requires requires { id (i) } // { dg-error "expected" }
+{
+  return i;
+}
+
+void g () {
+  f (42);
+}
+
+// { dg-excess-errors "" }
-- 
2.44.0


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

* Re: [PATCH] Fix PR c++/111106: missing ; causes internal compiler error
  2024-06-04  9:47       ` Simon Martin
@ 2024-06-04 14:18         ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2024-06-04 14:18 UTC (permalink / raw)
  To: Simon Martin; +Cc: gcc-patches

On 6/4/24 05:47, Simon Martin wrote:
> Hi Jason,
> 
> Thanks for the review.
> 
> On 31 May 2024, at 22:45, Jason Merrill wrote:
> 
>> On 5/30/24 07:31, Simon Martin wrote:
>>> 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.
>>
>> I don't see why implicit template parameters should be handled
>> differently from explicit ones here.
>>
>> This seems more like an error-recovery issue, and I'd be open to
>> adding || seen_error() to that assert like in various others.
>>
> Makes sense; this is what the attached updated patch (successfully
> tested on x86_64-pc-linux-gnu) does.
> 
> Is it better and OK for trunk?

OK.

Jason


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

end of thread, other threads:[~2024-06-04 14:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240530113143.17575-1-simon@nasilyan.com>
2024-05-30 11:31 ` [PATCH] Fix PR c++/111106: missing ; causes internal compiler error Simon Martin
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

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).