public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ICE with erroneous template redeclaration [PR106311]
@ 2022-07-15 15:29 Marek Polacek
  2022-07-22 12:35 ` Marek Polacek
  2022-07-22 21:21 ` Jason Merrill
  0 siblings, 2 replies; 5+ messages in thread
From: Marek Polacek @ 2022-07-15 15:29 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
to be error_mark_node in this ill-formed test.  I kept running into this
while reducing code, so it'd be good to have it fixed.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

	PR c++/106311

gcc/cp/ChangeLog:

	* pt.cc (redeclare_class_template): Check DECL_P before accessing
	DECL_SOURCE_LOCATION.

gcc/testsuite/ChangeLog:

	* g++.dg/template/redecl5.C: New test.
---
 gcc/cp/pt.cc                            | 3 ++-
 gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 718dfa5bfa8..0a294e91a79 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -6377,7 +6377,8 @@ redeclare_class_template (tree type, tree parms, tree cons)
 	{
 	  auto_diagnostic_group d;
 	  error ("template parameter %q+#D", tmpl_parm);
-	  inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
+	  inform (DECL_P (parm) ? DECL_SOURCE_LOCATION (parm) : input_location,
+		  "redeclared here as %q#D", parm);
 	  return false;
 	}
 
diff --git a/gcc/testsuite/g++.dg/template/redecl5.C b/gcc/testsuite/g++.dg/template/redecl5.C
new file mode 100644
index 00000000000..fb2d698e6bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/redecl5.C
@@ -0,0 +1,5 @@
+// PR c++/106311
+// { dg-do compile }
+
+template <typename, long> struct array; // { dg-error "template parameter" }
+template <typename, size_t X> struct array { }; // { dg-error "declared" }

base-commit: 23dd41c480fa9f06c33c1e6090bbae53869f85af
-- 
2.36.1


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

* Re: [PATCH] c++: ICE with erroneous template redeclaration [PR106311]
  2022-07-15 15:29 [PATCH] c++: ICE with erroneous template redeclaration [PR106311] Marek Polacek
@ 2022-07-22 12:35 ` Marek Polacek
  2022-07-22 21:21 ` Jason Merrill
  1 sibling, 0 replies; 5+ messages in thread
From: Marek Polacek @ 2022-07-22 12:35 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Ping.

On Fri, Jul 15, 2022 at 11:29:20AM -0400, Marek Polacek via Gcc-patches wrote:
> Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
> to be error_mark_node in this ill-formed test.  I kept running into this
> while reducing code, so it'd be good to have it fixed.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> 	PR c++/106311
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (redeclare_class_template): Check DECL_P before accessing
> 	DECL_SOURCE_LOCATION.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/redecl5.C: New test.
> ---
>  gcc/cp/pt.cc                            | 3 ++-
>  gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++
>  2 files changed, 7 insertions(+), 1 deletion(-)
>  create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 718dfa5bfa8..0a294e91a79 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -6377,7 +6377,8 @@ redeclare_class_template (tree type, tree parms, tree cons)
>  	{
>  	  auto_diagnostic_group d;
>  	  error ("template parameter %q+#D", tmpl_parm);
> -	  inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
> +	  inform (DECL_P (parm) ? DECL_SOURCE_LOCATION (parm) : input_location,
> +		  "redeclared here as %q#D", parm);
>  	  return false;
>  	}
>  
> diff --git a/gcc/testsuite/g++.dg/template/redecl5.C b/gcc/testsuite/g++.dg/template/redecl5.C
> new file mode 100644
> index 00000000000..fb2d698e6bc
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/redecl5.C
> @@ -0,0 +1,5 @@
> +// PR c++/106311
> +// { dg-do compile }
> +
> +template <typename, long> struct array; // { dg-error "template parameter" }
> +template <typename, size_t X> struct array { }; // { dg-error "declared" }
> 
> base-commit: 23dd41c480fa9f06c33c1e6090bbae53869f85af
> -- 
> 2.36.1
> 

Marek


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

* Re: [PATCH] c++: ICE with erroneous template redeclaration [PR106311]
  2022-07-15 15:29 [PATCH] c++: ICE with erroneous template redeclaration [PR106311] Marek Polacek
  2022-07-22 12:35 ` Marek Polacek
@ 2022-07-22 21:21 ` Jason Merrill
  2022-07-25 18:43   ` [v2 PATCH] " Marek Polacek
  1 sibling, 1 reply; 5+ messages in thread
From: Jason Merrill @ 2022-07-22 21:21 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches

On 7/15/22 11:29, Marek Polacek wrote:
> Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
> to be error_mark_node in this ill-formed test.  I kept running into this
> while reducing code, so it'd be good to have it fixed.
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> 
> 	PR c++/106311
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (redeclare_class_template): Check DECL_P before accessing
> 	DECL_SOURCE_LOCATION.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/redecl5.C: New test.
> ---
>   gcc/cp/pt.cc                            | 3 ++-
>   gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++
>   2 files changed, 7 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index 718dfa5bfa8..0a294e91a79 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -6377,7 +6377,8 @@ redeclare_class_template (tree type, tree parms, tree cons)
>   	{
>   	  auto_diagnostic_group d;
>   	  error ("template parameter %q+#D", tmpl_parm);
> -	  inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
> +	  inform (DECL_P (parm) ? DECL_SOURCE_LOCATION (parm) : input_location,
> +		  "redeclared here as %q#D", parm);

If we're checking DECL_P, probably we also should avoid passing it to 
%q#D if it's false?

>   	  return false;
>   	}
>   
> diff --git a/gcc/testsuite/g++.dg/template/redecl5.C b/gcc/testsuite/g++.dg/template/redecl5.C
> new file mode 100644
> index 00000000000..fb2d698e6bc
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/redecl5.C
> @@ -0,0 +1,5 @@
> +// PR c++/106311
> +// { dg-do compile }
> +
> +template <typename, long> struct array; // { dg-error "template parameter" }
> +template <typename, size_t X> struct array { }; // { dg-error "declared" }
> 
> base-commit: 23dd41c480fa9f06c33c1e6090bbae53869f85af


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

* [v2 PATCH] c++: ICE with erroneous template redeclaration [PR106311]
  2022-07-22 21:21 ` Jason Merrill
@ 2022-07-25 18:43   ` Marek Polacek
  2022-07-26  0:09     ` Jason Merrill
  0 siblings, 1 reply; 5+ messages in thread
From: Marek Polacek @ 2022-07-25 18:43 UTC (permalink / raw)
  To: Jason Merrill; +Cc: GCC Patches

On Fri, Jul 22, 2022 at 05:21:58PM -0400, Jason Merrill wrote:
> On 7/15/22 11:29, Marek Polacek wrote:
> > Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
> > to be error_mark_node in this ill-formed test.  I kept running into this
> > while reducing code, so it'd be good to have it fixed.
> > 
> > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
> > 
> > 	PR c++/106311
> > 
> > gcc/cp/ChangeLog:
> > 
> > 	* pt.cc (redeclare_class_template): Check DECL_P before accessing
> > 	DECL_SOURCE_LOCATION.
> > 
> > gcc/testsuite/ChangeLog:
> > 
> > 	* g++.dg/template/redecl5.C: New test.
> > ---
> >   gcc/cp/pt.cc                            | 3 ++-
> >   gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++
> >   2 files changed, 7 insertions(+), 1 deletion(-)
> >   create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C
> > 
> > diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> > index 718dfa5bfa8..0a294e91a79 100644
> > --- a/gcc/cp/pt.cc
> > +++ b/gcc/cp/pt.cc
> > @@ -6377,7 +6377,8 @@ redeclare_class_template (tree type, tree parms, tree cons)
> >   	{
> >   	  auto_diagnostic_group d;
> >   	  error ("template parameter %q+#D", tmpl_parm);
> > -	  inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
> > +	  inform (DECL_P (parm) ? DECL_SOURCE_LOCATION (parm) : input_location,
> > +		  "redeclared here as %q#D", parm);
> 
> If we're checking DECL_P, probably we also should avoid passing it to %q#D
> if it's false?

Right, I suppose printing "<error node>" isn't all that helpful.  How about
this?

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

-- >8 --
Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
to be error_mark_node in this ill-formed test.  I kept running into this
while reducing code, so it'd be good to have it fixed.

	PR c++/106311

gcc/cp/ChangeLog:

	* pt.cc (redeclare_class_template): Check DECL_P before accessing
	DECL_SOURCE_LOCATION.

gcc/testsuite/ChangeLog:

	* g++.dg/template/redecl5.C: New test.
---
 gcc/cp/pt.cc                            | 5 ++++-
 gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++
 2 files changed, 9 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index c415db304c9..6c581fe0fb7 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -6377,7 +6377,10 @@ redeclare_class_template (tree type, tree parms, tree cons)
 	{
 	  auto_diagnostic_group d;
 	  error ("template parameter %q+#D", tmpl_parm);
-	  inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
+	  if (DECL_P (parm))
+	    inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
+	  else
+	    inform (input_location, "redeclared here");
 	  return false;
 	}
 
diff --git a/gcc/testsuite/g++.dg/template/redecl5.C b/gcc/testsuite/g++.dg/template/redecl5.C
new file mode 100644
index 00000000000..fb2d698e6bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/redecl5.C
@@ -0,0 +1,5 @@
+// PR c++/106311
+// { dg-do compile }
+
+template <typename, long> struct array; // { dg-error "template parameter" }
+template <typename, size_t X> struct array { }; // { dg-error "declared" }

base-commit: 16aafa3194d4851a07cc204f56a5f0618f77e5d7
-- 
2.37.1


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

* Re: [v2 PATCH] c++: ICE with erroneous template redeclaration [PR106311]
  2022-07-25 18:43   ` [v2 PATCH] " Marek Polacek
@ 2022-07-26  0:09     ` Jason Merrill
  0 siblings, 0 replies; 5+ messages in thread
From: Jason Merrill @ 2022-07-26  0:09 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches

On 7/25/22 14:43, Marek Polacek wrote:
> On Fri, Jul 22, 2022 at 05:21:58PM -0400, Jason Merrill wrote:
>> On 7/15/22 11:29, Marek Polacek wrote:
>>> Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
>>> to be error_mark_node in this ill-formed test.  I kept running into this
>>> while reducing code, so it'd be good to have it fixed.
>>>
>>> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>>>
>>> 	PR c++/106311
>>>
>>> gcc/cp/ChangeLog:
>>>
>>> 	* pt.cc (redeclare_class_template): Check DECL_P before accessing
>>> 	DECL_SOURCE_LOCATION.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 	* g++.dg/template/redecl5.C: New test.
>>> ---
>>>    gcc/cp/pt.cc                            | 3 ++-
>>>    gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++
>>>    2 files changed, 7 insertions(+), 1 deletion(-)
>>>    create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C
>>>
>>> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
>>> index 718dfa5bfa8..0a294e91a79 100644
>>> --- a/gcc/cp/pt.cc
>>> +++ b/gcc/cp/pt.cc
>>> @@ -6377,7 +6377,8 @@ redeclare_class_template (tree type, tree parms, tree cons)
>>>    	{
>>>    	  auto_diagnostic_group d;
>>>    	  error ("template parameter %q+#D", tmpl_parm);
>>> -	  inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
>>> +	  inform (DECL_P (parm) ? DECL_SOURCE_LOCATION (parm) : input_location,
>>> +		  "redeclared here as %q#D", parm);
>>
>> If we're checking DECL_P, probably we also should avoid passing it to %q#D
>> if it's false?
> 
> Right, I suppose printing "<error node>" isn't all that helpful.  How about
> this?
> 
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

OK.

> -- >8 --
> Here we ICE trying to get DECL_SOURCE_LOCATION of the parm that happens
> to be error_mark_node in this ill-formed test.  I kept running into this
> while reducing code, so it'd be good to have it fixed.
> 
> 	PR c++/106311
> 
> gcc/cp/ChangeLog:
> 
> 	* pt.cc (redeclare_class_template): Check DECL_P before accessing
> 	DECL_SOURCE_LOCATION.
> 
> gcc/testsuite/ChangeLog:
> 
> 	* g++.dg/template/redecl5.C: New test.
> ---
>   gcc/cp/pt.cc                            | 5 ++++-
>   gcc/testsuite/g++.dg/template/redecl5.C | 5 +++++
>   2 files changed, 9 insertions(+), 1 deletion(-)
>   create mode 100644 gcc/testsuite/g++.dg/template/redecl5.C
> 
> diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
> index c415db304c9..6c581fe0fb7 100644
> --- a/gcc/cp/pt.cc
> +++ b/gcc/cp/pt.cc
> @@ -6377,7 +6377,10 @@ redeclare_class_template (tree type, tree parms, tree cons)
>   	{
>   	  auto_diagnostic_group d;
>   	  error ("template parameter %q+#D", tmpl_parm);
> -	  inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
> +	  if (DECL_P (parm))
> +	    inform (DECL_SOURCE_LOCATION (parm), "redeclared here as %q#D", parm);
> +	  else
> +	    inform (input_location, "redeclared here");
>   	  return false;
>   	}
>   
> diff --git a/gcc/testsuite/g++.dg/template/redecl5.C b/gcc/testsuite/g++.dg/template/redecl5.C
> new file mode 100644
> index 00000000000..fb2d698e6bc
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/template/redecl5.C
> @@ -0,0 +1,5 @@
> +// PR c++/106311
> +// { dg-do compile }
> +
> +template <typename, long> struct array; // { dg-error "template parameter" }
> +template <typename, size_t X> struct array { }; // { dg-error "declared" }
> 
> base-commit: 16aafa3194d4851a07cc204f56a5f0618f77e5d7


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

end of thread, other threads:[~2022-07-26  0:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 15:29 [PATCH] c++: ICE with erroneous template redeclaration [PR106311] Marek Polacek
2022-07-22 12:35 ` Marek Polacek
2022-07-22 21:21 ` Jason Merrill
2022-07-25 18:43   ` [v2 PATCH] " Marek Polacek
2022-07-26  0:09     ` 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).