Topic: Using declarations and the "struct stat hack
Author: mark@codesourcery.com
Date: Wed, 22 Jan 2003 18:47:28 +0000 (UTC) Raw View
Consider this code:
struct A { int i; struct i {}; };
struct B { int i; struct i {}; };
struct D : public A, public B { using A::i; void f (); };
void D::f () { struct i x; }
I can't find anything in the standard that says definitively what this
means. [namespace.udecl] says that a using-declaration shall
name "a member of a base class" -- but here we have two members, the
data member A::i and the class A::i.
Personally, I'd find it more attractive if this code did not work. I'd
like "using A::i" to mean "lookup A::i in the usual way and bind B::i to
that", which would mean that while "i = 3" would be valid in D::f,
"struct i x" would not be. However, if there were no A::i data member,
then "A::i" would find the struct and the code in D::f would be valid.
Thoughts?
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
---
[ 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, 22 Jan 2003 21:21:25 +0000 (UTC) Raw View
mark@codesourcery.com wrote:
> but here we have two members
I don't see why this should be any different than
when a using-declaration names a set of overloaded
functions.
---
[ 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: jhs@edg.com ("John H. Spicer")
Date: Thu, 23 Jan 2003 00:32:38 +0000 (UTC) Raw View
mark@codesourcery.com wrote:
> Consider this code:
>
> struct A { int i; struct i {}; };
> struct B { int i; struct i {}; };
> struct D : public A, public B { using A::i; void f (); };
> void D::f () { struct i x; }
>
> I can't find anything in the standard that says definitively what this
> means. [namespace.udecl] says that a using-declaration shall
> name "a member of a base class" -- but here we have two members, the
> data member A::i and the class A::i.
>
> Personally, I'd find it more attractive if this code did not work. I'd
> like "using A::i" to mean "lookup A::i in the usual way and bind B::i to
> that", which would mean that while "i = 3" would be valid in D::f,
> "struct i x" would not be. However, if there were no A::i data member,
> then "A::i" would find the struct and the code in D::f would be valid.
>
> Thoughts?
>
I agree with you, but unfortunately the standard committee did not.
I remembered that this was discussed by the committee and that a resolution was
adopted that was different than what I hoped for, but I had a hard time finding
definitive wording in the standard.
I went back though my records and found the paper that proposed a resolution and
the associated committee motion that adopted the proposed resolution The paper
is N0905, and "option 1" from that paper was adopted at the Stockholm meeting in
July of 1996. The resolution is that "using A::i" brings in everything named i
from A.
3.4.3.2p2 was modified to implement this resolution, but interestingly that only
covers the namespace case and not the class case. I think the class case was
overlooked when the wording was drafted. A core issue should be opened to make
sure the class case is handled properly.
John Spicer
Edison Design Group
---
[ 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 ]