gcc/kcc difference
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Fri Dec 31 23:54:00 GMT 1999
> "../bug2.cc", line 7: error: more than one instance of overloaded function
> "Unipolar" matches the argument list:
> function "Unipolar(int)"
> function "A::Unipolar(int)"
> argument types are: (int)
> return Unipolar(x);
> ^
> detected during instantiation of "int A::B(X) [with X=int]" at line
> 17
> ------------------------------
>
> Which is correct?
I believe g++ (and your program) is correct. Unipolar is a dependent
name, since it is used in a function call involving type-dependent
expressions (14.6.2/1). So it is bound at instantiation time, which
kcc correctly attempts.
Now, I don't know why kcc considers ::Unipolar(int) a candidate. It
might be because of 14.6.4/1:
# In resolving dependent names, names from the following sources are
# considered:
# - Declarations that are visible at the point of definition of the
# template.
# - Declarations from namespaces associated with the types of the
# function arguments both from the instanÃÂtiation context (14.6.4.1)
# and from the definition context.
So both :: and A:: are considered when resolving Unipolar. However,
14.6.4.2 explains
# For a function call that depends on a template parameter, if the
# function name is an unqualifiedÃÂid but not a templateÃÂid, the
# candidate functions are found using the usual lookup rules (3.4.1,
# 3.4.2) except that:
# - For the part of the lookup using unqualified name lookup (3.4.1),
# only function declarations with external linkage from the template
# definition context are found.
# - For the part of the lookup using associated namespaces (3.4.2), only
# function declarations with external linkage found in either the
# template definition context or the template instantiation context
# are found.
So ::Unipolar is not even found (it does not appear in the template
definition context). Even if it was found, it would still be hidden by
the static member according to the usual lookup rules.
BTW, if A::Unipolar is removed, the program has undefined behaviour.
Regards,
Martin
More information about the Gcc
mailing list