|
 |
On Fri, 16 May 2008 08:46:09 +0200, Warp <war### [at] tag povray org> wrote:
> Warp <war### [at] tag povray org> 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
|
 |