* [C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089)
@ 2007-11-20 10:14 Jakub Jelinek
2007-11-20 11:43 ` Mark Mitchell
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2007-11-20 10:14 UTC (permalink / raw)
To: Jason Merrill, Mark Mitchell; +Cc: gcc-patches
Hi!
xref_basetypes relies on the first argument being aggregate type,
but on invalid testcases like the attached one cp_parser_class_specifier
can contain various other types (in this case LANG_TYPE - a type
of OVERLOAD).
As begin_class_definition has all the needed code to report diagnostics
and have sane error recovery and cp_parser_class_specifier calls it shortly
after this, I think the best fix for this is instead of duplicating
such checks and error recovery just not call xref_basetypes for
non-aggregates at all and just let begin_class_definition do its job.
Bootstrapped/regtested on x86_64-linux, ok for trunk?
2007-11-19 Jakub Jelinek <jakub@redhat.com>
PR c++/34089
* parser.c (cp_parser_class_specifier): Don't call xref_basetypes
if type is not aggregate type.
* g++.dg/template/crash74.C: New test.
--- gcc/cp/parser.c.jj 2007-11-08 01:19:18.000000000 +0100
+++ gcc/cp/parser.c 2007-11-19 17:47:34.000000000 +0100
@@ -14134,7 +14134,7 @@ cp_parser_class_specifier (cp_parser* pa
/* Process the base classes. If they're invalid, skip the
entire class body. */
- if (!xref_basetypes (type, bases))
+ if (IS_AGGR_TYPE (type) && !xref_basetypes (type, bases))
{
/* Consuming the closing brace yields better error messages
later on. */
--- gcc/testsuite/g++.dg/template/crash74.C.jj 2007-11-19 17:53:27.000000000 +0100
+++ gcc/testsuite/g++.dg/template/crash74.C 2007-11-19 17:54:38.000000000 +0100
@@ -0,0 +1,6 @@
+// PR c++/34089
+// { dg-do compile }
+// { dg-options "" }
+
+template<typename F> void foo () { }
+template<typename F> struct foo<F> { }; // { dg-error "template class without a name|abstract decl" }
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089)
2007-11-20 10:14 [C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089) Jakub Jelinek
@ 2007-11-20 11:43 ` Mark Mitchell
2007-11-20 16:57 ` [C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089, take 2) Jakub Jelinek
0 siblings, 1 reply; 4+ messages in thread
From: Mark Mitchell @ 2007-11-20 11:43 UTC (permalink / raw)
To: Jakub Jelinek; +Cc: Jason Merrill, gcc-patches
Jakub Jelinek wrote:
> 2007-11-19 Jakub Jelinek <jakub@redhat.com>
>
> PR c++/34089
> * parser.c (cp_parser_class_specifier): Don't call xref_basetypes
> if type is not aggregate type.
>
> * g++.dg/template/crash74.C: New test.
This seems like it would work, but why are we event accepting this code
in cp_parser_class_head?
+template<typename F> void foo () { }
+template<typename F> struct foo<F> { };
Here, we know that foo is not a name for a class template, so we should
be able to detect the error at that point.
Thanks,
--
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713
^ permalink raw reply [flat|nested] 4+ messages in thread
* [C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089, take 2)
2007-11-20 11:43 ` Mark Mitchell
@ 2007-11-20 16:57 ` Jakub Jelinek
2007-11-20 19:19 ` Mark Mitchell
0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2007-11-20 16:57 UTC (permalink / raw)
To: Mark Mitchell; +Cc: Jason Merrill, gcc-patches
On Mon, Nov 19, 2007 at 09:01:58PM -0800, Mark Mitchell wrote:
> Jakub Jelinek wrote:
>
> > 2007-11-19 Jakub Jelinek <jakub@redhat.com>
> >
> > PR c++/34089
> > * parser.c (cp_parser_class_specifier): Don't call xref_basetypes
> > if type is not aggregate type.
> >
> > * g++.dg/template/crash74.C: New test.
>
> This seems like it would work, but why are we event accepting this code
> in cp_parser_class_head?
>
> +template<typename F> void foo () { }
> +template<typename F> struct foo<F> { };
>
> Here, we know that foo is not a name for a class template, so we should
> be able to detect the error at that point.
Like this?
2007-11-20 Jakub Jelinek <jakub@redhat.com>
PR c++/34089
* parser.c (cp_parser_class_head): Reject function template ids.
* g++.dg/template/crash74.C: New test.
--- gcc/cp/parser.c.jj 2007-11-20 11:31:07.000000000 +0100
+++ gcc/cp/parser.c 2007-11-20 14:51:47.000000000 +0100
@@ -14536,8 +14536,18 @@ cp_parser_class_head (cp_parser* parser,
/* Look up the type. */
if (template_id_p)
{
- type = TREE_TYPE (id);
- type = maybe_process_partial_specialization (type);
+ if (TREE_CODE (id) == TEMPLATE_ID_EXPR
+ && (DECL_FUNCTION_TEMPLATE_P (TREE_OPERAND (id, 0))
+ || TREE_CODE (TREE_OPERAND (id, 0)) == OVERLOAD))
+ {
+ error ("function template %qD redeclared as a class template", id);
+ type = error_mark_node;
+ }
+ else
+ {
+ type = TREE_TYPE (id);
+ type = maybe_process_partial_specialization (type);
+ }
if (nested_name_specifier)
pushed_scope = push_scope (nested_name_specifier);
}
--- gcc/testsuite/g++.dg/template/crash74.C.jj 2007-11-20 14:08:53.000000000 +0100
+++ gcc/testsuite/g++.dg/template/crash74.C 2007-11-20 14:52:25.000000000 +0100
@@ -0,0 +1,6 @@
+// PR c++/34089
+// { dg-do compile }
+// { dg-options "" }
+
+template<typename F> void foo () { }
+template<typename F> struct foo<F> { }; // { dg-error "redeclared as" }
Jakub
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-11-20 15:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-20 10:14 [C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089) Jakub Jelinek
2007-11-20 11:43 ` Mark Mitchell
2007-11-20 16:57 ` [C++ PATCH] Avoid ice-on-invalid in xref_basetypes (PR c++/34089, take 2) Jakub Jelinek
2007-11-20 19:19 ` Mark Mitchell
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).