C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

conformance question

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Jimen Ching
Guest





PostPosted: Sun Feb 15, 2004 5:29 pm    Post subject: conformance question Reply with quote



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) [email]jching (AT) flex (DOT) com[/email] [email]wh6brr (AT) uhm (DOT) ampr.org[/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
Alberto Barbati
Guest





PostPosted: Sun Feb 15, 2004 9:32 pm    Post subject: Re: conformance question Reply with quote



Jimen Ching wrote:

Quote:
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 ]


Back to top
Francis Glassborow
Guest





PostPosted: Sun Feb 15, 2004 10:17 pm    Post subject: Re: conformance question Reply with quote



In article <102tfsc7430a0fc (AT) corp (DOT) supernews.com>, Jimen Ching
<jching (AT) flex (DOT) com> writes
Quote:
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.)
Quote:
---------------------------
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 ]


Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.