* [PATCH] Fix PR c++/42054: ICE with invalid template parameter
@ 2009-11-22 21:51 Simon Martin
2009-11-22 22:36 ` Gabriel Dos Reis
0 siblings, 1 reply; 6+ messages in thread
From: Simon Martin @ 2009-11-22 21:51 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 449 bytes --]
Hello,
The following invalid snippet causes an ICE with gcc >= 4.3
=== cut here ===
template<int int> struct A;
template<int int> struct A;
=== cut here ===
This is due to 'redeclare_class_template' not handling cases with an
invalid template argument. The attached patch fixes this by skipping
invalid template arguments.
I have successfully regtested it on 86_64-apple-darwin-9. Is it OK
for trunk?
Best regards,
Simon
:ADDPATCH c++:
[-- Attachment #2: CL_42054 --]
[-- Type: text/plain, Size: 148 bytes --]
2009-11-22 Simon Martin <simartin@users.sourceforge.net>
PR c++/42054
* pt.c (redeclare_class_template): Skip erroneous template parameters.
[-- Attachment #3: pr42054.patch --]
[-- Type: text/plain, Size: 408 bytes --]
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c (revision 154425)
+++ gcc/cp/pt.c (working copy)
@@ -4565,7 +4565,8 @@
return false;
}
- if (tmpl_default != NULL_TREE && parm_default != NULL_TREE)
+ if (tmpl_parm != error_mark_node
+ && tmpl_default != NULL_TREE && parm_default != NULL_TREE)
{
/* We have in [temp.param]:
[-- Attachment #4: CL_42054_testsuite --]
[-- Type: text/plain, Size: 114 bytes --]
2009-11-21 Simon Martin <simartin@users.sourceforge.net>
PR c++/42054:
* g++.dg/parse/error37.C: New test.
[-- Attachment #5: error37.C --]
[-- Type: text/plain, Size: 170 bytes --]
/* PR c++/42054 */
/* { dg-do "compile" } */
template<int int> struct A; /* { dg-error "two or more" } */
template<int int> struct A; /* { dg-error "two or more" } */
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/42054: ICE with invalid template parameter
2009-11-22 21:51 [PATCH] Fix PR c++/42054: ICE with invalid template parameter Simon Martin
@ 2009-11-22 22:36 ` Gabriel Dos Reis
2009-11-28 16:39 ` Simon Martin
0 siblings, 1 reply; 6+ messages in thread
From: Gabriel Dos Reis @ 2009-11-22 22:36 UTC (permalink / raw)
To: Simon Martin; +Cc: GCC Patches
On Sun, Nov 22, 2009 at 3:49 PM, Simon Martin
<simartin@users.sourceforge.net> wrote:
> Hello,
>
> The following invalid snippet causes an ICE with gcc >= 4.3
>
> === cut here ===
> template<int int> struct A;
> template<int int> struct A;
> === cut here ===
>
> This is due to 'redeclare_class_template' not handling cases with an
> invalid template argument. The attached patch fixes this by skipping
> invalid template arguments.
>
> I have successfully regtested it on 86_64-apple-darwin-9. Is it OK
> for trunk?
>
> Best regards,
> Simon
>
> :ADDPATCH c++:
>
>
>
> 2009-11-22 Simon Martin <simartin@users.sourceforge.net>
>
> PR c++/42054
> * pt.c (redeclare_class_template): Skip erroneous template
> parameters.
>
>
>
> Index: gcc/cp/pt.c
> ===================================================================
> --- gcc/cp/pt.c (revision 154425)
> +++ gcc/cp/pt.c (working copy)
> @@ -4565,7 +4565,8 @@
> return false;
> }
>
> - if (tmpl_default != NULL_TREE && parm_default != NULL_TREE)
> + if (tmpl_parm != error_mark_node
> + && tmpl_default != NULL_TREE && parm_default != NULL_TREE)
Instead of adding one layer of more predicates (that get repeated, at the risk
of forgetting to check), why don't you just do an early return
when tmpl_parm is an error_mark_node?
-- Gaby
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/42054: ICE with invalid template parameter
2009-11-22 22:36 ` Gabriel Dos Reis
@ 2009-11-28 16:39 ` Simon Martin
2009-12-20 20:14 ` Simon Martin
2010-02-23 5:01 ` [PATCH] " Jason Merrill
0 siblings, 2 replies; 6+ messages in thread
From: Simon Martin @ 2009-11-28 16:39 UTC (permalink / raw)
To: gdr; +Cc: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 565 bytes --]
Hello Gabriel,
>> - if (tmpl_default != NULL_TREE && parm_default != NULL_TREE)
>> + if (tmpl_parm != error_mark_node
>> + && tmpl_default != NULL_TREE && parm_default != NULL_TREE)
>
> Instead of adding one layer of more predicates (that get repeated, at the risk
> of forgetting to check), why don't you just do an early return
> when tmpl_parm is an error_mark_node?
You're right, thanks for your remark.
The attached patch does that. I have successfully regtested it on
86_64-apple-darwin-9. Is it OK for trunk?
Best regards,
Simon
[-- Attachment #2: CL_42054_2 --]
[-- Type: text/plain, Size: 170 bytes --]
2009-11-28 Simon Martin <simartin@users.sourceforge.net>
PR c++/42054
* pt.c (redeclare_class_template): Return false if there are erroneous
template parameters.
[-- Attachment #3: pr42054_2.patch --]
[-- Type: text/plain, Size: 1746 bytes --]
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c (revision 154425)
+++ gcc/cp/pt.c (working copy)
@@ -4543,22 +4543,24 @@
continue;
tmpl_parm = TREE_VALUE (TREE_VEC_ELT (tmpl_parms, i));
+ if (tmpl_parm == error_mark_node)
+ return false;
+
parm = TREE_VALUE (TREE_VEC_ELT (parms, i));
tmpl_default = TREE_PURPOSE (TREE_VEC_ELT (tmpl_parms, i));
parm_default = TREE_PURPOSE (TREE_VEC_ELT (parms, i));
/* TMPL_PARM and PARM can be either TYPE_DECL, PARM_DECL, or
TEMPLATE_DECL. */
- if (tmpl_parm != error_mark_node
- && (TREE_CODE (tmpl_parm) != TREE_CODE (parm)
- || (TREE_CODE (tmpl_parm) != TYPE_DECL
- && !same_type_p (TREE_TYPE (tmpl_parm), TREE_TYPE (parm)))
- || (TREE_CODE (tmpl_parm) != PARM_DECL
- && (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (tmpl_parm))
- != TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm))))
- || (TREE_CODE (tmpl_parm) == PARM_DECL
- && (TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (tmpl_parm))
- != TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm))))))
+ if (TREE_CODE (tmpl_parm) != TREE_CODE (parm)
+ || (TREE_CODE (tmpl_parm) != TYPE_DECL
+ && !same_type_p (TREE_TYPE (tmpl_parm), TREE_TYPE (parm)))
+ || (TREE_CODE (tmpl_parm) != PARM_DECL
+ && (TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (tmpl_parm))
+ != TEMPLATE_TYPE_PARAMETER_PACK (TREE_TYPE (parm))))
+ || (TREE_CODE (tmpl_parm) == PARM_DECL
+ && (TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (tmpl_parm))
+ != TEMPLATE_PARM_PARAMETER_PACK (DECL_INITIAL (parm)))))
{
error ("template parameter %q+#D", tmpl_parm);
error ("redeclared here as %q#D", parm);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/42054: ICE with invalid template parameter
2009-11-28 16:39 ` Simon Martin
@ 2009-12-20 20:14 ` Simon Martin
2010-02-19 20:11 ` [PING^2, PATCH] " Simon Martin
2010-02-23 5:01 ` [PATCH] " Jason Merrill
1 sibling, 1 reply; 6+ messages in thread
From: Simon Martin @ 2009-12-20 20:14 UTC (permalink / raw)
To: GCC Patches
Ping? (http://gcc.gnu.org/ml/gcc-patches/2009-11/msg01595.html)
Thanks,
Simon
On 11/28/09 5:18 PM, Simon Martin wrote:
> Hello Gabriel,
>
>>> - if (tmpl_default != NULL_TREE && parm_default != NULL_TREE)
>>> + if (tmpl_parm != error_mark_node
>>> + && tmpl_default != NULL_TREE && parm_default != NULL_TREE)
>>
>> Instead of adding one layer of more predicates (that get repeated, at
>> the risk
>> of forgetting to check), why don't you just do an early return
>> when tmpl_parm is an error_mark_node?
> You're right, thanks for your remark.
>
> The attached patch does that. I have successfully regtested it on
> 86_64-apple-darwin-9. Is it OK for trunk?
>
> Best regards,
> Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PING^2, PATCH] Fix PR c++/42054: ICE with invalid template parameter
2009-12-20 20:14 ` Simon Martin
@ 2010-02-19 20:11 ` Simon Martin
0 siblings, 0 replies; 6+ messages in thread
From: Simon Martin @ 2010-02-19 20:11 UTC (permalink / raw)
To: gcc-patches
Ping? (http://gcc.gnu.org/ml/gcc-patches/2009-11/msg01595.html)
Thanks,
Simon
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Fix PR c++/42054: ICE with invalid template parameter
2009-11-28 16:39 ` Simon Martin
2009-12-20 20:14 ` Simon Martin
@ 2010-02-23 5:01 ` Jason Merrill
1 sibling, 0 replies; 6+ messages in thread
From: Jason Merrill @ 2010-02-23 5:01 UTC (permalink / raw)
To: Simon Martin; +Cc: gdr, GCC Patches
OK, thanks. Please feel free to ping me directly on C++ patches.
Jason
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-02-23 3:35 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-22 21:51 [PATCH] Fix PR c++/42054: ICE with invalid template parameter Simon Martin
2009-11-22 22:36 ` Gabriel Dos Reis
2009-11-28 16:39 ` Simon Martin
2009-12-20 20:14 ` Simon Martin
2010-02-19 20:11 ` [PING^2, PATCH] " Simon Martin
2010-02-23 5:01 ` [PATCH] " 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).