Re: trees example
From: B. v Ingen Schenau (bart_at_ingen.ddns.info)
Date: 11/28/03
- Next message: B. v Ingen Schenau: "Re: Member template instantiation confusion"
- Previous message: B. v Ingen Schenau: "Re: What a translation unit is."
- In reply to: Richard Heathfield: "Re: trees example"
- Next in thread: Guy Harrison: "Re: trees example"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/
- Next message: B. v Ingen Schenau: "Re: Member template instantiation confusion"
- Previous message: B. v Ingen Schenau: "Re: What a translation unit is."
- In reply to: Richard Heathfield: "Re: trees example"
- Next in thread: Guy Harrison: "Re: trees example"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|