This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Specialization in templates
- To: Joe Buck <jbuck at Synopsys dot COM>
- Subject: Re: Specialization in templates
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 31 Oct 1998 05:30:04 -200
- Cc: un9i at rz dot uni-karlsruhe dot de, egcs at cygnus dot com, egcs-patches at cygnus dot com
- References: <199810301718.JAA05523@atrus.synopsys.com>
Joe Buck <jbuck@Synopsys.COM> writes:
>>
>> Matthias Seeger <un9i@rz.uni-karlsruhe.de> writes:
>>
>> > template<class T> class A<T*> { };
>>
>> > my EGCS compiler stops with "parse error before <'"
>>
>> And it is correct.
> Yes, but ideally the compiler would give a better error message for
> this case, one that would help the user more.
>> > Does this mean that templete specialization (Stroustrup, 3rd ed.,
>> > p.341) is not yet supported by EGCS?
>>
>> Nope; specialization is supported, but, in order to specialize a
>> template, you must first declare it.
> Maybe some sort of error recovery pattern could be added that would
> recognize that this is an attempt to specialize a template that has
> not been declared.
Ok, I managed to introduce a modification in the grammar that catches
this case, and prints an error message. However, after that, the
template processing prints another error message that I can't find a
way to avoid :-(
oliva@tiete% ./cc1plus -quiet ~/t.cc
/home/phd/oliva/t.cc:1: template class A was not declared yet
/home/phd/oliva/t.cc:1: template class without a name
The problem is that finish_template_type generates an error_mark_node
because it cannot find template class A. Then, begin_class_definition
creates an anonymous class, and push_template_decl_real ends up
complaining about it... Can anyone else proceed from this point?
BTW, the only conflict introduced by this patch is:
state 233
apparent_template_type -> identifier . '<' template_arg_list_opt '>' .finish_template_type (rule 173)
named_class_head_sans_basetype -> aggr identifier . (rule 492)
'<' shift, and go to state 498
'<' [reduce using rule 492 (named_class_head_sans_basetype)]
$default reduce using rule 492 (named_class_head_sans_basetype)
Since named_class_head_sans_basetype cannot be followed by a `<'
meaning angle bracket, and no regressions were introduced, it seems to
me that the conflict is resolved correctly.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:oliva@gnu.org mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil
invalid-spec.diff