Topic: ?Re: Does the text of 14.6.2 3 contradict the example?
Author: "kanze" <kanze@gabi-soft.fr>
Date: Thu, 17 Aug 2006 12:24:03 CST Raw View
Ian Collins wrote:
> The text of sub-clause 14.6.2 3 states that "if a base class
> of this template depends on a template-parameter, the base
> class scope is not examined during name lookup until the class
> template is instantiated."
> Which implies to me that the base class scope is included in
> the name lookup.
It seems to say very clearly that the base class scope is NOT
included in the name lookup until instantiation, that is, that
it is NOT included in name lookup for non-dependent names (which
takes place when the template is defined, before any
instantiation).
> But the example clearly states that in the following:
> #include <iostream>
> typedef double A;
> template <typename T> struct B {
> typedef T A;
> };
> template <typename T> struct D : B<T> {
> static const A a;
> };
> int main() {
> D<char> d;
> std::cout << sizeof d.a << std::endl;
> }
> A::a will be double.
It says that D::a will have a type double, for any instantiation
of the template. That's because in the declaration of D::a, A
is not a dependent name. It is thus looked up before
instantiation, the base class is not considered, and the
compiler finds the typedef.
Note that this is a change compared to what was usual in
earlier, pre-standard implementations, where no name lookup took
place before instantiation.
> I tried this with gcc and Sun CC, with gcc sizeof d.a is 8
> (double) and with CC it is 1 (char).
> Which is correct?
gcc is conform to the current standard. Sun CC is catching up,
but is still not there; apparently the version you have doesn't
implement two phased lookup yet. (The version I use doesn't
earlier, but it is not the latest version from Sun.)
Note too that Sun is usually very concerned about not breaking
existing code. Even if the compiler implements the new name
lookup, you may need a special option to get it.
--
James Kanze GABI Software
Conseils en informatique orient e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S mard, 78210 St.-Cyr-l' cole, France, +33 (0)1 30 23 00 34
---
[ 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.comeaucomputing.com/csc/faq.html ]