Topic: Friend declarations
Author: Martin von Loewis <loewis@informatik.hu-berlin.de>
Date: 1999/07/31 Raw View
Christoph Schulz <kristov@gmx.net> writes:
> I'm rather confused about friend declarations. The Standard says:
[...]
> I can't see how these statements fit together.
This is indeed confusing; see a recent thread "Defect Report:..." in
this group for another aspect of that problem.
In this case, the contradiction is not too serious: Both citations are
Notes, so you'd expect normative text explaining what is really going
on. Indeed, 7.3.1.2/3 provides those details, together with 3.4.2.
> Additionally, there is
> an example demonstrating unqualified name lookup in 3.4.1/3 :
>
> typedef int f; // (1)
> struct A {
> friend void f(A &); // (2)
> operator int();
> void g(A a) {
> f(a); // Standard says "f" is taken to be the typedef
> }
> };
>
> Is this example correct when in namespace scope? "f" is expected to be
> a typedef name (1). If (2) introduces a function name into the
> enclosing namespace, then there are a typedef name and a (invisible)
> function name in the same declarative region. According to 3.3/4 the
> program is ill-formed in (2).
I agree this is ill-formed. I believe there is already an issue on
that example in the issues list, where an additional scope is put
around (or inside?) A.
Regards,
Martin
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: wmm@fastdial.net
Date: 1999/08/02 Raw View
In article <37A1DB36.BA9FFCD0@gmx.net>,
Christoph Schulz <kristov@gmx.net> wrote:
> Okay, but try to imagine you have to write a C++ compiler. How
> would you implement friends? (I use two different compilers and
> both complain about declaring the friend with the same name as
> the typedef.)
>
> > typedef int f; // (1)
> > struct A {
> > friend void f(A &); // (2)
> > operator int();
> > void g(A a) {
> > f(a); // Standard says "f" is taken to be the
typedef
> > }
> > };
>
> I noticed something beyond: if "f" is a typedef (as the Standard
> states) "f(a);" is a declaration like "int a;" and *not* a
> cast-expression as stated in 3.4.1/3. I think so because of the
> ambiguity resolution described in 6.8. The result is to declare an
> identifier "a" in the outermost block of a function that has a
> parameter "a". This is an error (3.3.2/2).
I don't think there will be any dissent from the idea that that
example is incorrect, for both the reasons you cited. However,
I don't think any compiler writer would be misled by this example
into implementing friends incorrectly; the normative part of the
Standard is clear enough to allow a reasonable reader to determine
that the example is wrong.
> Do I have to post a Defect Report?
No. As I said, it's already been noted, it will be on the next
issues list, and I expect that it will be fixed in the Technical
Corrigendum that will be issued in a year or two.
--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: wmm@fastdial.net
Date: 1999/07/30 Raw View
In article <379EF048.C3BE9944@gmx.net>,
Christoph Schulz <kristov@gmx.net> wrote:
> I'm rather confused about friend declarations. The Standard says:
>
> "[...] friend declarations [...] may introduce a (possibly not
visible)
> name into an enclosing namespace" (3.3/4 Note)
>
> and:
>
> "friend declarations refer to functions or classes that are members of
> the nearest enclosing namespace, but they do not introduce new names
> into that namespace." (3.3.1/6)
>
> I can't see how these statements fit together. Additionally, there is
> an example demonstrating unqualified name lookup in 3.4.1/3 :
>
> typedef int f; // (1)
> struct A {
> friend void f(A &); // (2)
> operator int();
> void g(A a) {
> f(a); // Standard says "f" is taken to be the
typedef
> }
> };
>
> Is this example correct when in namespace scope? "f" is expected to be
> a typedef name (1). If (2) introduces a function name into the
> enclosing namespace, then there are a typedef name and a (invisible)
> function name in the same declarative region. According to 3.3/4 the
> program is ill-formed in (2). If (2), however, does not introduce a
> name, then it should be OK, but it's useless because I'm not allowed
to
> *define* the friend - its name would clash with the type "f".
>
> I would be very happy if someone could help me understanding this.
These are questions that have no official answers yet. However,
they will be on the next revision of the Core Language Issues
List, and I expect that we will discuss them in detail at the
next meeting (in October). Whether we will resolve the issues
at that time or not is something I won't try to predict.
(There's been an active discussion of friends among the Committee
for the last few months, and both these questions have been noted
during that discussion.)
--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Christoph Schulz <kristov@gmx.net>
Date: 1999/07/30 Raw View
wmm@fastdial.net wrote:
>
> In article <379EF048.C3BE9944@gmx.net>,
> Christoph Schulz <kristov@gmx.net> wrote:
> > I'm rather confused about friend declarations. The Standard says:
> >
> > "[...] friend declarations [...] may introduce a (possibly not
> > visible) name into an enclosing namespace" (3.3/4 Note)
> >
> > and:
> >
> > "friend declarations refer to functions or classes that are members
> > of the nearest enclosing namespace, but they do not introduce new
> > names into that namespace." (3.3.1/6)
> >
> > I can't see how these statements fit together.
> > [...]
>
> These are questions that have no official answers yet. However,
> they will be on the next revision of the Core Language Issues
> List, and I expect that we will discuss them in detail at the
> next meeting (in October). Whether we will resolve the issues
> at that time or not is something I won't try to predict.
>
> (There's been an active discussion of friends among the Committee
> for the last few months, and both these questions have been noted
> during that discussion.)
Okay, but try to imagine you have to write a C++ compiler. How
would you implement friends? (I use two different compilers and
both complain about declaring the friend with the same name as
the typedef.)
> typedef int f; // (1)
> struct A {
> friend void f(A &); // (2)
> operator int();
> void g(A a) {
> f(a); // Standard says "f" is taken to be the typedef
> }
> };
I noticed something beyond: if "f" is a typedef (as the Standard
states) "f(a);" is a declaration like "int a;" and *not* a
cast-expression as stated in 3.4.1/3. I think so because of the
ambiguity resolution described in 6.8. The result is to declare an
identifier "a" in the outermost block of a function that has a
parameter "a". This is an error (3.3.2/2).
Do I have to post a Defect Report?
--
Chris
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Christoph Schulz <kristov@gmx.net>
Date: 1999/07/28 Raw View
Hello!
I'm rather confused about friend declarations. The Standard says:
"[...] friend declarations [...] may introduce a (possibly not visible)
name into an enclosing namespace" (3.3/4 Note)
and:
"friend declarations refer to functions or classes that are members of
the nearest enclosing namespace, but they do not introduce new names
into that namespace." (3.3.1/6)
I can't see how these statements fit together. Additionally, there is
an example demonstrating unqualified name lookup in 3.4.1/3 :
typedef int f; // (1)
struct A {
friend void f(A &); // (2)
operator int();
void g(A a) {
f(a); // Standard says "f" is taken to be the typedef
}
};
Is this example correct when in namespace scope? "f" is expected to be
a typedef name (1). If (2) introduces a function name into the
enclosing namespace, then there are a typedef name and a (invisible)
function name in the same declarative region. According to 3.3/4 the
program is ill-formed in (2). If (2), however, does not introduce a
name, then it should be OK, but it's useless because I'm not allowed to
*define* the friend - its name would clash with the type "f".
I would be very happy if someone could help me understanding this.
--
Chris
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html ]