Topic: conformance question
Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Sun, 15 Feb 2004 21:32:53 +0000 (UTC) Raw View
Jimen Ching wrote:
> I compiled this with GCC 2.95.4, and I got an error about func()
> and data being private. But GCC 3.3.3pre doesn't give any errors.
> I've also compiled this with VC++ 6 and it gives an error. But
> VC++ 7 doesn't. Since the later versions are supposed to be more
> standards conforming, this suggests that this access is allowed.
> But reading the standard seems to say otherwise. So is the newer
> versions of the compilers wrong, or am I misinterpreting the standard?
You are interepreting the standard correctly. However, there is a defect
report about this issue:
http://std.dkuug.dk/jtc1/sc22/wg21/docs/cwg_defects.html#45
It seems that all those compilers have already implemented the proposed
resolution, against the current wording of the standard. I guess that's
good and it's a pity that this DR hasn't made it into TC1.
Alberto
---
[ 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: francis@robinton.demon.co.uk (Francis Glassborow)
Date: Sun, 15 Feb 2004 22:17:47 +0000 (UTC) Raw View
In article <102tfsc7430a0fc@corp.supernews.com>, Jimen Ching
<jching@flex.com> writes
>Hi,
>
>I was wondering if the following code is allowed by the standard.
As currently formulated nested classes have no access privileges. Worse
according to a strict reading of the Standard there is no way to grant
that access (can only be granted sideways or outwards by friend
declarations). That will be fixed (by removing the lack of access) but
for now you must make the nested class a friend of the enclosing class
(and compilers violate the Standard by accepting that declaration, well
they better or else a great deal of code is both broken and
irreparable.)
>---------------------------
>class cl
> {
>public:
> cl() : s(this) {}
> operator int() { return 0; }
>
>private:
> int data;
> void func(void) {}
>
> struct st
> {
> cl *cl_ptr;
> st(cl *p) { cl_ptr = p; }
> void func(void) { cl_ptr->func(); }
> void func2(void) { cl_ptr->data++; }
> };
> st s;
> };
>
>int main() { cl c; return c; }
>---------------------------
>
>I compiled this with GCC 2.95.4, and I got an error about func()
>and data being private. But GCC 3.3.3pre doesn't give any errors.
>I've also compiled this with VC++ 6 and it gives an error. But
>VC++ 7 doesn't. Since the later versions are supposed to be more
>standards conforming, this suggests that this access is allowed.
>But reading the standard seems to say otherwise. So is the newer
>versions of the compilers wrong, or am I misinterpreting the standard?
>
>Thanks in advance.
>
>--jc
--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects
---
[ 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: jching@flex.com (Jimen Ching)
Date: Sun, 15 Feb 2004 17:29:21 +0000 (UTC) Raw View
Hi,
I was wondering if the following code is allowed by the standard.
---------------------------
class cl
{
public:
cl() : s(this) {}
operator int() { return 0; }
private:
int data;
void func(void) {}
struct st
{
cl *cl_ptr;
st(cl *p) { cl_ptr = p; }
void func(void) { cl_ptr->func(); }
void func2(void) { cl_ptr->data++; }
};
st s;
};
int main() { cl c; return c; }
---------------------------
I compiled this with GCC 2.95.4, and I got an error about func()
and data being private. But GCC 3.3.3pre doesn't give any errors.
I've also compiled this with VC++ 6 and it gives an error. But
VC++ 7 doesn't. Since the later versions are supposed to be more
standards conforming, this suggests that this access is allowed.
But reading the standard seems to say otherwise. So is the newer
versions of the compilers wrong, or am I misinterpreting the standard?
Thanks in advance.
--jc
--
Jimen Ching (WH6BRR) jching@flex.com wh6brr@uhm.ampr.org
---
[ 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 ]