Protected constructor access rules changed?
Mark Mitchell
mmitchell@usa.net
Thu Feb 5 17:44:00 GMT 1998
>>>>> "Mike" == Mike Stump <mrs@wrs.com> writes:
Mike> I was wrong. Rick is correct. I was confused.
Mike> Egcs should allow his code. In the standard we can find:
Mike> 12 Special member functions [special]
Mike> 2 Special member functions obey the usual access rules (11).
Mike> [Example: declaring a constructor protected ensures that
Mike> only derived classes and friends can create objects using
Mike> it. ]
This definitely conflicts with the words I found. Oh well. I do
think that perhaps you're correct, i.e., that the intent is that this
should work.
Mike> This reads fairly straight forwardly and unambiguously. I
Mike> don't dispute the words people found, but the standard is
Mike> flawed in this area. I will see about generating a DR for
Mike> it when I'm in Frace next month at the ANSI meeting. In the
Mike> meantime, please accept my apologies, and this fix:
Shouldn't your patch handle destructors, and assignment operators?
Also, what about constructors other than the default
and copy constructor? These are *not* `special member functions' by
the definition in the CD2 document (I haven't had a chance to check
a more-up-to-date version yet). I don't see why they should be
treated differently; just that this may be another problem in the
wording in the standard.
Mike> Thu Feb 5 14:38:23 1998 Mike Stump <mrs@wrs.com>
Mike> * search.c (compute_access): Handle protected
Mike> constructors in derived classes as accessible.
Mike> Doing diffs in search.c.~1~: *** search.c.~1~ Mon Feb 2
Mike> 17:23:21 1998 --- search.c Thu Feb 5 14:37:20 1998
Mike> *************** compute_access (basetype_path, field) ***
Mike> 977,983 **** else if (TREE_PROTECTED (field)) { if
Mike> (current_class_type ! && static_mem &&
Mike> ACCESSIBLY_DERIVED_FROM_P (context, current_class_type))
Mike> PUBLIC_RETURN; else --- 977,983 ---- else if (TREE_PROTECTED
Mike> (field)) { if (current_class_type ! && (static_mem ||
Mike> DECL_CONSTRUCTOR_P (field)) && ACCESSIBLY_DERIVED_FROM_P
Mike> (context, current_class_type)) PUBLIC_RETURN; else
Mike> --------------
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu
More information about the Gcc-bugs
mailing list