Re: Scope of class template static data members
On Jul 16, 12:02 pm, Ian Collins <ian-n...@hotmail.com> wrote:
James Kanze wrote:
[...]
At the point of instantiation. Non-dependent name lookup occurs
at the point of definition, and only at the point of definition.
If you make the name dependent in some way (e.g. "X<N>::called",
or "this->called") name lookup is deferred to the point of
instantiation, and the name in the base class is found.
True, but I've never really seen the benefit of that change.
I wouldn't say that there is no benefit, but...
So that's the reason, I never could see why. I hope CC keeps
on with the old way, I bet there's a lot of code on Solaris
that relies on it. That includes a lot of mine!
Two phase lookup just leads to a lot of unnecessarily verbose
and cluttered code for no real gain.
IMHO, the real problem is that it isn't immediately clear what
is dependent, and what isn't. And you need subtle tricks (like
putting "this->" in front of the access to a static member) to
force dependency. Had you been required to declare dependency
explicitly, I could accept it.
(IMHO, the cure is worse than the disease: in my experience,
name hijacking was never a real problem anyway, and the
standard solution doesn't really solve it either. And of
course, I would never deliver a template without having
tested it thoroughly, much less without having instantiated
it. Any errors that the compiler can catch at the
definition point wouldn't have gotten through my unit tests,
so it doesn't really matter.)
Ah, so we agree.
More or less. IMHO, it's a steep price we pay for relatively
little benefit.
To be fair to the committee, when they first raised the idea,
and made it clear that some form of two phased lookup would be
adopted, there were very, very few implementations of templates
around, so they sort of had to guess what the problems might be.
And it's not really their fault if, having made it clear that
the final standard would have two phased lookup, all of the
implementors plunged in and implemented templates without it, so
we'd have the portability problem. (At the time two phased
lookup was proposed, I think CFront was the only compiler with
templates. Which meant Sun CC, of course, so we'd still have
the cost of upgrading. But why organizations like Microsoft or
g++ introduced templates in a way that ensured that they'd have
to later break code, I don't know.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34