Topic: Access checking of constructor and destructor
Author: "Johannes Schaub (litb)" <schaub-johannes@web.de>
Date: Sun, 7 Mar 2010 21:39:02 CST Raw View
Hello all. I'm confused about how access checking for the constructor and
destructor is done. First of all, uses of a constructor in expressions are
done without using a name, but clause 12 says in 12/3 "Special member
functions obey the usual access rules". What are these "usual" rules?
1) Is the following valid?
class A { A() { } ~A() { } };
void f(A = A());
int main() { f(); }
The Standard (all n3035 here) says at 11/8 "The names in a default argument
expression (8.3.6) are bound at the point of declaration, and access is
checked at that point rather than at any points of use of the default
argument expression."
2) Is the following valid?
struct A { };
struct B : private virtual A { };
struct C : B { C() { } ~C() { } };
Closed issue http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#7
says it is intended that it fails, but still it works with comeau and gcc
(all that i tried). My read of the Standard is that it should work, but i'm
not sure on that ( http://stackoverflow.com/questions/2371176/c-private-
virtual-inheritance-problem/2371368#2371368 ).
3) Is the following valid?
struct A { protected: A() { } };
struct B : A { void f() { new A; } };
Protected names are accessible in derived classes. Special rules are there
for nonstatic data or function members. But 11.5 seem to imply there is a
class-member access or qualified-id to them for this special restriction to
take place.
So is the code valid? GCC and comeau disagree and reject it.
Thanks for all answers in advance!
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]