This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Specialization in templates


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]