Re: trees example

From: B. v Ingen Schenau (bart_at_ingen.ddns.info)
Date: 11/28/03


Date: Fri, 28 Nov 2003 20:32:08 +0100

Richard Heathfield wrote:

> B. v Ingen Schenau wrote:
>
>> Richard Heathfield wrote:
>>
>>>
>>> /* This code compiles cleanly (amazingly enough) under g++ 2.95.3 using
>>> * -W -Wall -ansi -pedantic -O2, so it should be pretty portable to most
>>> * modern C++ compilers. Oh, and it seems to work, too, which is always
>>> * a bonus. It was surprisingly pleasant to write. Perhaps there is
>>> * something to this C++ lark after all.
>>> */
>>
>> Actually, your overloaded, and templated, operator<< causes the overload
>> resolution for my compilers to fail. Tested with Comeau (online, v4.3.3)
>> and gcc (v3.3.2) both in strict mode.
>
> Does this reflect a change in the language, or is it a bug in g++ 2.95.3,
> or is it just plain old undefined behaviour?

I think it is a bug in g++ 2.95.3, but the specifications on overloading
and templates are such a mess that in comparisson the C standard reads like
a bed-time story.

One of the problems related to templates and overloading is at what moment
the compiler actually instantiates the templates.
My understanding of the matter (and you might want to verify that in
c.l.c++.m) is that instantiation only happens *after* one of the overloads
has been selected.
This is mainly to avoid that the compiler has to emit a diagnostic for a
template instantiation that would be thrown away after the overload
resolution. The drawback is that it is possible that a template gets chosen
for (or breaks) overload resolution that can not be validly instantiated.

What g++ 2.95.3 seems to do is to instantiate the templates *before* the
overload resolution.

Bart v Ingen Schenau

-- 
a.c.l.l.c-c++ FAQ: http://www.snurse-l.org/acllc-c++/faq.html
a.c.l.l.c-c++ FAQ mirror: http://nullptr.merseine.nu:8080/acllcc++.html
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/


Relevant Pages

  • Re: trees example
    ... Actually, your overloaded, and templated, operator<< causes the overload ... resolution for my compilers to fail. ... > TreeException e; ... a.c.l.l.c-c++ FAQ mirror: http://nullptr.merseine.nu:8080/acllcc++.html ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Vacation
    ... have only 2 clients and I can usually get at least a few days, up to perhaps a week, but the overload when I get back makes me wonder if it is worth it. ... The docs never wanted to use the hospital transcription department because they wouldn't let them use templates at that time, and templates were a huge time saver. ...
    (sci.med.transcription)
  • Re: partial specialization
    ... templates: member functions can be overloaded, ... way to uniquely specify which overload you are specializing: ...
    (microsoft.public.vc.language)
  • Re: operator overloading
    ... > is i want to overload new int, ... only the standard C programming language, ... netiquette before posting to any of these newsgroups. ... you should read the group's charter and FAQ, ...
    (comp.lang.c)
  • Re: template specialization
    ... >> Second, if you're dealing with a class heirarchy, why do you need to ... Can't you just overload the function? ... I use templates because I don't want to have to ... Item 41 says "Differentiate between inheritance and templates" -- the ...
    (comp.lang.cpp)