Topic: Address of overloaded function and dependent names
Author: Michiel.Salters@logicacmg.com (Michiel Salters)
Date: Tue, 1 Jun 2004 17:06:40 +0000 (UTC) Raw View
stephan.bergmann@sun.com (Stephan Bergmann) wrote in message news:<c94fvj$2hk$1@new-usenet.uk.sun.com>...
> Hi all.
>
> In the following program,
>
> void f(int) {}
> template<typename T> struct C {
> static void (*g())(T) { return static_cast<void (*)(T)>(f); }
> };
> void f(double) {}
> int main() {
> C<double>::g();
> }
>
> should the use of f in C::g be considered the use of a dependent name or
> not?
No. An expression is dependant if the conditions of 14.6.2 Dependent names
( plus the applicable paragraphs below ) are met. The expression (f)
could be covered by 14.6.2.2, Type-dependent expressions. It doesn't
contain any of the 4 parts listed in 14.6.2.2/3, so it is not dependent.
The larger expression static_cast<void (*)(T)>(f) is dependent, but
that doesn't affect the lookup of any non-dependent subexpression.
That means in less formal words that name lookup must start at all
leaves of an expression, and be completed as far as possible during
the compilation of the template. A dependent name does not stop lookup
in different subtrees, only in the trees it belongs to.
Regards,
Michiel Salters
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: stephan.bergmann@sun.com (Stephan Bergmann)
Date: Wed, 2 Jun 2004 15:10:37 +0000 (UTC) Raw View
Michiel Salters wrote:
> stephan.bergmann@sun.com (Stephan Bergmann) wrote in message news:<c94fvj$2hk$1@new-usenet.uk.sun.com>...
>
>>Hi all.
>>
>>In the following program,
>>
>>void f(int) {}
>>template<typename T> struct C {
>> static void (*g())(T) { return static_cast<void (*)(T)>(f); }
>>};
>>void f(double) {}
>>int main() {
>> C<double>::g();
>>}
>>
>>should the use of f in C::g be considered the use of a dependent name or
>>not?
>
>
> No. An expression is dependant if the conditions of 14.6.2 Dependent names
> ( plus the applicable paragraphs below ) are met. The expression (f)
> could be covered by 14.6.2.2, Type-dependent expressions. It doesn't
> contain any of the 4 parts listed in 14.6.2.2/3, so it is not dependent.
>
> The larger expression static_cast<void (*)(T)>(f) is dependent, but
> that doesn't affect the lookup of any non-dependent subexpression.
That's what I feared. Does anybody know whether this behavior is by
intent, or is an omission in the Standard? To me, it would appear to be
more natural if the somewhat special, context-dependent rules to
determine the address of an overloaded function name (13.4) were
complemented by a special rule for the dependence of that function name.
(Btw, this problem breaks the code of OpenOffice.org, which worked
just fine on a variety of C++ compilers, until gcc 3.4.0 came along...)
-Stephan
[...]
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: hyrosen@mail.com (Hyman Rosen)
Date: Wed, 2 Jun 2004 17:29:22 +0000 (UTC) Raw View
Stephan Bergmann wrote:
> (Btw, this problem breaks the code of OpenOffice.org, which worked just
> fine on a variety of C++ compilers, until gcc 3.4.0 came along...)
Well, Comeau is clearly confused. The following "works",
void f(int);
template<typename T> struct C { static void (*g())(T) { return f; } };
void f(double);
int main() { C<double>::g(); }
but the following does not,
template<typename T> struct C { static void (*g())(T) { return f; } };
void f(double);
int main() { C<double>::g(); }
complaining in the template that identifier "f" is undefined. If "f" were
truly a dependent name, why should omitting the first declaration matter?
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: stephan.bergmann@sun.com (Stephan Bergmann)
Date: Thu, 27 May 2004 18:02:35 +0000 (UTC) Raw View
Hi all.
In the following program,
void f(int) {}
template<typename T> struct C {
static void (*g())(T) { return static_cast<void (*)(T)>(f); }
};
void f(double) {}
int main() {
C<double>::g();
}
should the use of f in C::g be considered the use of a dependent name or
not?
Gcc 3.3.3 and Comeau 4.3.3 obviously consider it to be a dependent name,
at the place of instantiation of C<double> consider both overloads of f,
and compile the program just fine. But gcc 3.4.0 obviously considers it
to be a non-dependent name, at the place of instantiation of C<double>
consider only f(int), and rejects the program as requiering a
static_cast from void()(int) to void()(double).
Anybody any idea who's right?
-Stephan
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]