Re: Two phase name lookup and signature
pstade.mb@gmail.com wrote:
I have a question about two-phase name lookup.
namespace abc {
template< class T >
void bar();
}
template< class T >
void foo(T x)
{
abc::bar(std::string(), x); // may be diagnosed in 1st phase?
}
Comeau on line, GCC3.4.4 and VC++7.1/8 compiles.
They, of course, fail to compile when 'foo' is instantiated.
I'm not too sure. The function call, itself, is part of a
type dependent expression, I think that this means that overload
resolution cannot occur until instantiation, which would account
for your not getting an error earlier. On the other hand, if
I've understood correctly, a qualified function name cannot be
type dependent, so the set of overloaded functions is determined
in the first phase.
The logic is understandable. In your case, it's obvious, given
the set of overloaded functions, that the call cannot
succeed---it has two arguments, and there is no overloaded
function which can be called with two arguments, regardless of
type. Compilers don't work that way, however---they either do
overload resolution or they don't, and it should be obvious that
the compiler cannot do overload resolution until it knows the
actual type of x.
Is this code conforming?
Conforming in what sense. It's obviously illegal, for all
possible instantiations of foo. I think it's illegal even if
the user defines an additional overload of abc::bar() which
could be called, if the declaration is only present after the
definition of the foo(). On the other hand, there's no
requirement that the compiler actually diagnose an error until
the function is instantiated, and in fact, I don't think that it
is allowed to.
or should be avoided?
Templates with no possible legal instantiation should probably
be avoided, if that's what you mean.
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orientie objet/
Beratung in objektorientierter Datenverarbeitung
9 place Simard, 78210 St.-Cyr-l'Icole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]