POV-Ray : Newsgroups : povray.off-topic : A question about Java generics (not a flame) : Re: A question about Java generics (not a flame) Server Time
7 Sep 2024 19:15:05 EDT (-0400)
  Re: A question about Java generics (not a flame)  
From: Fredrik Eriksson
Date: 16 May 2008 13:28:46
Message: <op.ua9b57dj7bxctx@e6600.bredbandsbolaget.se>
On Fri, 16 May 2008 08:46:09 +0200, Warp <war### [at] tagpovrayorg> wrote:
> Warp <war### [at] tagpovrayorg> wrote:
>
>   In one file I have this:
>
> // ----- file1.cc -----
> #include <iostream>
>
> template<typename T>
> void foo(T t)
> {
>     bar(t);
> }
>
> void bar(int i) { std::cout << "int: " << i << std::endl; }
>
> void b();
>
> int main()
> {
>     foo(5);
>     b();
> }
> // --------------------
>
>   And in another file I have this:
>
> // ----- file2.cc -----
> #include <iostream>
>
> template<typename T>
> void foo(T t)
> {
>     bar(t);
> }
>
> void bar(long i) { std::cout << "long: " << i << std::endl; }
>
> void b()
> {
>     foo(7);
> }
> // --------------------

Your example is ill-formed according to the very paragraph you yourself  
quoted in another post. You have multiple instantiations of 'foo<int>',  
but they have different meanings. Also, since the overloads of 'bar' are  
spread out, section 14.6.4.2 applies as well:

"If the call would be ill-formed or would find a better match had the  
lookup within the associated namespaces considered all the function  
declarations with external linkage introduced in those namespaces in all  
translation units, not just considering those declarations found in the  
template definition and template instantiation contexts, then the program  
has undefined behavior."



>   I have to admit I don't know if gcc is behaving correctly here.

In this case it does not matter, as the example is ill-formed. Note  
however that few C++ compilers correctly implement two-phase lookup.



-- 
FE


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.