 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Mirek Fidler Guest
|
Posted: Sun Jul 20, 2003 9:27 am Post subject: Re: qualified function names and two phase lookup |
|
|
|> > #include <vector>
| Quote: | #include
is different than
#include
#include
Nifty, huh?
This starts to get scary.
Starts? I consider myself probably better than average, and I'm
totally incapable of understanding what happens in name lookup in
templates more than half the time. I rather suspect that we've ended
up with something so complicated that it cannot be safely used in real
projects.
|
What about sweeping out all this dependent / non-dependent stuff and
return to method older/brokne compilers use anyway, that is deffering
everything to the point instatiation ?
I think that most problems w.r.t. templates are due to the fact that
as (perhaps) last minute change comitee decided that it would be a good
idea to check templates even when they are not instantiated. And perhaps
that it is bad that templates depened on order of declaration.
Well, I am not sure what problems were really solved. Templates
still depend on order of declarations. Compile time checking of
templates sometimes works, but not always.
I really had no problems using compilers that perform just
instatiation-point checks and resolutions. My problems started with
compilers that are compliant....
Mirek
---
[ 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 ]
|
|
| Back to top |
|
 |
Mirek Fidler Guest
|
Posted: Sun Jul 20, 2003 12:14 pm Post subject: Re: qualified function names and two phase lookup |
|
|
| Quote: | What about sweeping out all this dependent / non-dependent stuff
and
return to method older/brokne compilers use anyway, that is
deffering
everything to the point instatiation ?
That just moves the "problem" to your implementation files. What if
*they* also include different headers?
|
Yeas, but I think I can rather handle this than all that
dependent/non-dependent names lookup complications....
I believe that without this, all chapter 14 would be reduced by 50%
and even moderately good programmer as me could finally use templates
without danger that more conforming C++ implementation will break all
his code again...
| Quote: | Also, it is important for export that the compiler considers what is
visible in the template's implementation file.
|
You mean that "export" that no compiler supported for 5 years after
the standard release and nobody ever needed ?!
| Quote: | Well, I am not sure what problems were really solved. Templates
still depend on order of declarations.
Not only templates!
|
Hey, I agree with this. What I wanted to say is that if this problem
is present in other code, why in the world standard tries to be smarter
than is needed ?
Mirek
---
[ 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 ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Sun Jul 20, 2003 9:23 pm Post subject: Re: qualified function names and two phase lookup |
|
|
[email]cxl (AT) volny (DOT) cz[/email] ("Mirek Fidler") writes:
| Quote: | I think that most problems w.r.t. templates are due to the fact that
as (perhaps) last minute change comitee decided that it would be a good
idea to check templates even when they are not instantiated. And perhaps
that it is bad that templates depened on order of declaration.
|
I don't know where and when it started, I've been seeing confusion or
misinformation like the above being repeated more than often.
The notion of 2-phase name lookup was already considered in the dark
ages. The main difference with what was considered at the time is
that now not just operators may be dependent, but also functions used
in certain way and that in meantime we've got Argument Dependent Name
Lookup -- characterizing ADL as a "template baby" is a good recipe for
confusion.
At the time they were speaking of "bound symbols" (roughly what we call
"dependent name" nowadays), and "free symbols" ("non-dependent name"
in contemporary terms). Free symbols were supposed to be resolved in
the context of the template definition, and the bound symbols were
supposed to be resolved in the instantiation context.
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/1992/N0209.ps
I find the above mentioned paper very instructive on understanding
what were the general design criteria and the philophical basis.
--
Gabriel Dos Reis, [email]gdr (AT) integrable-solutions (DOT) net[/email]
---
[ 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 ]
|
|
| Back to top |
|
 |
Mirek Fidler Guest
|
Posted: Mon Jul 21, 2003 5:54 am Post subject: Re: qualified function names and two phase lookup |
|
|
| Quote: | | I think that most problems w.r.t. templates are due to the fact
that
| as (perhaps) last minute change comitee decided that it would be a
good
| idea to check templates even when they are not instantiated. And
perhaps
| that it is bad that templates depened on order of declaration.
I don't know where and when it started, I've been seeing confusion or
misinformation like the above being repeated more than often.
|
I must apologize, I do not know exact history. It is just it seems
so as it would be last minute change, given all chapter 14 content and
endless confusion about it...
Mirek
---
[ 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 ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Mon Jul 21, 2003 6:32 pm Post subject: Re: qualified function names and two phase lookup |
|
|
[email]cxl (AT) volny (DOT) cz[/email] ("Mirek Fidler") writes:
| Quote: | Well, I am not sure what problems were really solved. Templates
still depend on order of declarations.
Not only templates!
Hey, I agree with this. What I wanted to say is that if this problem
is present in other code, why in the world standard tries to be smarter
than is needed ?
|
I've seen no evidence that the "standard tires to be smarter
than is needed" as far as the template machinery is concerned. On the
other hand, I've seen repeated assertions with no technical foundation.
--
Gabriel Dos Reis, [email]gdr (AT) integrable-solutions (DOT) net[/email]
---
[ 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 ]
|
|
| Back to top |
|
 |
Mirek Fidler Guest
|
Posted: Mon Jul 21, 2003 8:34 pm Post subject: Re: qualified function names and two phase lookup |
|
|
| Quote: | | Hey, I agree with this. What I wanted to say is that if this
problem
| is present in other code, why in the world standard tries to be
smarter
| than is needed ?
I've seen no evidence that the "standard tires to be smarter
than is needed" as far as the template machinery is concerned. On the
other hand, I've seen repeated assertions with no technical
foundation. |
What I wanted to say is that I do not see any advantage that
two-phase lookup would give to me as opposed to simple
instatiation-point lookup.
If there are any advantages I do not see yet, please go on and show
me them.
Mirek
---
[ 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 ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Wed Jul 23, 2003 3:37 pm Post subject: Re: qualified function names and two phase lookup |
|
|
[email]cxl (AT) volny (DOT) cz[/email] ("Mirek Fidler") wrote in message
news:<bff24j$du3fh$1 (AT) ID-198693 (DOT) news.uni-berlin.de>...
| Quote: | | I think that most problems w.r.t. templates are due to the
| fact that as (perhaps) last minute change comitee decided that it
| would be a good idea to check templates even when they are not
| instantiated. And perhaps that it is bad that templates depened on
| order of declaration.
I don't know where and when it started, I've been seeing confusion
or misinformation like the above being repeated more than often.
I must apologize, I do not know exact history. It is just it seems
so as it would be last minute change, given all chapter 14 content and
endless confusion about it...
|
I guess it depends on what you mean by "last minute change". Chapter 14
didn't get its final wording into very late in the game. That doesn't
mean that nothing in it was discussed or considered earlier. It does
mean that compiler implementors couldn't get started earlier, with the
results that even today, no two compilers seem to implement exactly the
same thing. (As Gaby correctly points out, a lot of the changes are due
to the addition of namespaces. Let's face it, no one had any concrete
experience of how namespaces would work with two phase lookup in
templates, given that both were complete innovations by the committee,
so some experimentation was necessary.)
It's probably worth pointing out that most of the discussion outside of
the committee centered on all of the new things you could do with
standard C++. Two phase lookup doesn't add any new functionality, so it
didn't get any lead articles in C++ Report. Even today, I suspect that
most older programmers first learn about it when it hits them. This is
a shame, but I don't see what could have been done about it.
--
James Kanze GABI Software mailto:kanze (AT) gabi-soft (DOT) fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16
---
[ 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 ]
|
|
| Back to top |
|
 |
kanze@gabi-soft.fr Guest
|
Posted: Wed Jul 23, 2003 7:04 pm Post subject: Re: qualified function names and two phase lookup |
|
|
[email]gdr (AT) integrable-solutions (DOT) net[/email] (Gabriel Dos Reis) wrote in message
news:<m3smp12xwy.fsf (AT) uniton (DOT) integrable-solutions.net>...
| Quote: | cxl (AT) volny (DOT) cz ("Mirek Fidler") writes:
| > > Well, I am not sure what problems were really
| > > solved. Templates still depend on order of declarations.
| > Not only templates!
| Hey, I agree with this. What I wanted to say is that if this
| problem is present in other code, why in the world standard tries to
| be smarter than is needed ?
I've seen no evidence that the "standard tires to be smarter than is
needed" as far as the template machinery is concerned. On the other
hand, I've seen repeated assertions with no technical foundation.
|
I don't think that there can be a "technical foundation", since the
problem isn't really technical. In introducing two phase look-up, the
standard introduced a change with regards to existing practice. The
motivation for the change was, as far as I can tell, to reduce the risk
of "name hijacking" -- of the template instantiation accidentally
picking up a local name at the instantiation point. The means involved
were:
- separate names into dependant and non-dependant,
- do all non-dependant lookup in the template definition context, and
- do dependant lookup globally in the definition context, and using
only ADL in the instantiation context.
As with any change, there are costs, and there are (hopefully)
benefits. Not all of which are technical. On the costs side:
Added complexity for the user:
There are really two aspects here: it is not trivially obvious what
is dependant, and what isn't, so sometimes the compiler will not
find a name I expect it to (because it is using dependant lookup),
and the fact that at the instantiation context, only ADL lookup is
used (lack of orthogonality in the lookup rules -- again, the
compiler fails to find a name I expect it to find.
If the names are to be divided into two categories, for different
types of look-up, I'd much prefer that the division be more
explicit.
Added complexity for the implementor:
I'm just guessing about this, but I cannot imagine how two phase
lookup could fail to more complex than the older situation.
This has repercusions for the user as well: at present, it is
difficult to find two compilers which do exactly the same thing.
Breaks existing code:
Also a problem, although I think that most, if not all cases where
the code is broken will result in a compiler error. While it isn't
difficult to construct cases where code silently breaks, I don't
think that they are very frequent in practice.
The price is, in sum, very high.
As for the benefits, it does reduce the risk of name hijacking. The
potential problem is real, but I've seen no evidence, or for that
matter, no real indication, that it is anything but potential. In
practice, it isn't a problem in small projects, and it is a general
problem, not limited to templates in large projects, with the result
that any successful large project already has some political mechanisms
for dealing with the problem. (In my own experience, mostly in projects
of more than 500 KLoc, I've only seen one case of a name conflict. And
that was due to a macro in an X11 header -- two phase lookup doesn't
help with regards to macros.)
In sum, two phase look-up is a very expensive solution to a problem that
didn't exist in practice.
--
James Kanze GABI Software mailto:kanze (AT) gabi-soft (DOT) fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16
---
[ 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 ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Thu Jul 24, 2003 2:11 am Post subject: Re: qualified function names and two phase lookup |
|
|
[email]kanze (AT) gabi-soft (DOT) fr[/email] writes:
| Quote: | It's probably worth pointing out that most of the discussion outside of
the committee centered on all of the new things you could do with
standard C++. Two phase lookup doesn't add any new functionality, so it
didn't get any lead articles in C++ Report. Even today, I suspect that
most older programmers first learn about it when it hits them. This is
a shame, but I don't see what could have been done about it.
|
Better explanation outside the inner circle of template gurus?
--
Gabriel Dos Reis, [email]gdr (AT) integrable-solutions (DOT) net[/email]
---
[ 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 ]
|
|
| Back to top |
|
 |
Daveed Vandevoorde Guest
|
Posted: Thu Jul 24, 2003 2:13 am Post subject: Re: qualified function names and two phase lookup |
|
|
[email]cxl (AT) volny (DOT) cz[/email] ("Mirek Fidler") wrote:
| Quote: | | Hey, I agree with this. What I wanted to say is that if this
problem
| is present in other code, why in the world standard tries to be
smarter
| than is needed ?
I've seen no evidence that the "standard tires to be smarter
than is needed" as far as the template machinery is concerned. On the
other hand, I've seen repeated assertions with no technical
foundation.
What I wanted to say is that I do not see any advantage that
two-phase lookup would give to me as opposed to simple
instatiation-point lookup.
If there are any advantages I do not see yet, please go on and show
me them.
|
Two-phase lookup helps address three problems:
(a) Parsing templates in their generic form.
Parsing " X * p;" requires the knowledge of whether X is a type
or not. If you delay all your lookups to the point of instantiation
you cannot parse this thing in contexts that allow both declarations
and expressions (such as function definitions).
The first compiler to implement a form of two-phase name lookup
was the HP aC++ compiler (it wasn't quite the standard scheme,
but it was fairly close; early 1997). When the aC++ engineers fed
popular template libraries to the compiler, they found that _all_ of
them contained basic syntax errors that had never been detected by
other compilers. (Which means that parts of these libraries had
never been instantiated even though they had been around for years!)
Some very recent compilers still accept the following code:
template<typename T> void f() {
X * p
g()
}
(the missing semicolons are intentional).
(b) Accidental name capture.
(See also a post by James Kanze in this thread.)
Basically, the template writer gets more control over some of the names
used in a template definition since they cannot be hijacked by the
instantiation context.
(c) A template separation model.
In a separation model (unlike an inclusion model), the definition context
is not accessible for ordinary lookup during instantiation (since the
definition has been compiled already).
IOW, two-phase lookup was essential for "export."
("C++ Templates: The Complete Guide" introduces many of these issues,
as well as some of the history.)
Daveed
---
[ 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 ]
|
|
| Back to top |
|
 |
Daveed Vandevoorde Guest
|
Posted: Fri Jul 25, 2003 8:16 pm Post subject: Re: qualified function names and two phase lookup |
|
|
[email]cxl (AT) volny (DOT) cz[/email] ("Mirek Fidler") wrote:
[...]
| Quote: | Are there any *real* problem that are solved by two-phase lookup ?
|
See also my other posting that lists three broad issues.
| Quote: | Only benefit I can see so far is the possibility to detect some bugs at
compile time, in case that concrete thing does not get instantiated, but
such bugs seldom has any influence on code correctness.
|
I have found that it has a tremendous impact on my coding cycle:
Discovering a basic syntax error while I develop a template is far
less frustrating than discovering it when I test the whole thing.
Like I said in the other posting: Prior to compilers supporting two-
phase name lookup a large number of template libraries were
shipping with templates that contained basic syntax errors.
A standard-conforming compiler would have saved quite a bit
of embarassment.
| Quote: | Are there any
any other *practical* benefits of two-phase lookup as opposed to single
instantiation point lookup ? (as implemented in e.g. GCC)
|
It enables separate compilation of templates. That in turn enables
(but does not require) faster build times and non-source object
file representations of templates.
It also enables compiler implementations that represent templates
in parsed form instead of as a token stream. The advantage of
that is that template instantiation becomes a considerably cheaper
(read: faster!) process. Some compilers do this today.
Daveed
---
[ 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 ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Sat Jul 26, 2003 12:52 am Post subject: Re: qualified function names and two phase lookup |
|
|
[email]kanze (AT) gabi-soft (DOT) fr[/email] writes:
[...]
| Quote: | I (like many other older programmers) am also bothered by the fact that
it breaks a lot of my existing code.
|
That is interesting. In which ways does it break them?
I would really like to understand how you wrote them and how trhey are
now broken. I'm not implying you don't have such code, I'm just
curious about the way you wrote them and the sort of assumptions you
made. (I've already seen code not compiling any more with GCC-3.4, but I
tend to think there were too many unspoken assumptions).
| Quote: | Again, breaking code should have
been considered a high cost, and should have weighed heavily against two
phase lookup. But here again, more early discussion would have helped.
|
"more early" than 1992 would mean?
(The reference I gave is one of the oldest reference publically
reachable, I would not be surprised that discussions related to that
paper started even earlier, bringing us in 1991 or 1990, i.e. when
committee works started).
| Quote: | All of my template code was actually written after the first discussions
concerning two phase lookup in the standards working group, and had I
known that this was a possibility, I would have (hopefully) written my
code so that it worked both ways.
|
Just curious: You mean, you never wrote any template code after early
1992?
Let's face it: templates were an experimental feature when proposed
for standardization; as such it was expected that rules would change.
--
Gabriel Dos Reis, [email]gdr (AT) integrable-solutions (DOT) net[/email]
---
[ 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 ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Sat Jul 26, 2003 12:53 am Post subject: Re: qualified function names and two phase lookup |
|
|
[email]google (AT) vandevoorde (DOT) com[/email] (Daveed Vandevoorde) writes:
[...]
| Quote: | Are there any
any other *practical* benefits of two-phase lookup as opposed to single
instantiation point lookup ? (as implemented in e.g. GCC)
It enables separate compilation of templates.
|
Maybe it would help if people remember that in 1992, the issue of
separate or not separate compilation of templates was not on
explicilty the table, because the separate compilation of template was
implied as the default (mostly in the mind of the people who wrote the
reference I gave).
[...]
| Quote: | It also enables compiler implementations that represent templates
in parsed form instead of as a token stream. The advantage of
that is that template instantiation becomes a considerably cheaper
(read: faster!) process. Some compilers do this today.
|
I wish there were more "communications" on the basics of templates.
Hopefully, your book will fill the gap.
--
Gabriel Dos Reis, [email]gdr (AT) integrable-solutions (DOT) net[/email]
---
[ 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 ]
|
|
| Back to top |
|
 |
Mirek Fidler Guest
|
Posted: Mon Jul 28, 2003 7:07 pm Post subject: Re: qualified function names and two phase lookup |
|
|
| Quote: | Only benefit I can see so far is the possibility to detect some bugs
at
compile time, in case that concrete thing does not get instantiated,
but
such bugs seldom has any influence on code correctness.
I have found that it has a tremendous impact on my coding cycle:
Discovering a basic syntax error while I develop a template is far
less frustrating than discovering it when I test the whole thing.
|
In fact, I found this very enjoyable too :)
| Quote: | It enables separate compilation of templates. That in turn enables
(but does not require) faster build times and non-source object
file representations of templates.
It also enables compiler implementations that represent templates
in parsed form instead of as a token stream. The advantage of
that is that template instantiation becomes a considerably cheaper
(read: faster!) process. Some compilers do this today.
|
But I do not believe in real benefits of above two.
Simply said - I do not like this tradeoff :)
OTOH, two-phase lookup is here and unlikely to go away. Case is lost
:)
Mirek
---
[ 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 ]
|
|
| Back to top |
|
 |
Gabriel Dos Reis Guest
|
Posted: Tue Jul 29, 2003 1:34 am Post subject: Re: qualified function names and two phase lookup |
|
|
[email]cxl (AT) volny (DOT) cz[/email] ("Mirek Fidler") writes:
| Quote: | Simply said - I do not like this tradeoff
|
Then, you will find yourself frequently in trouble with C++ :-)
--
Gabriel Dos Reis, [email]gdr (AT) integrable-solutions (DOT) net[/email]
---
[ 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 ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|