Commit 056a3b12 by Mark Mitchell Committed by Mark Mitchell

* class.c (maybe_warn_about_overly_private_class): Reformat.

From-SVN: r22502
parent 3add5845
1998-09-20 Mark Mitchell <mark@markmitchell.com>
* class.c (maybe_warn_about_overly_private_class): Reformat.
1998-09-17 Andrew MacLeod <amacleod@cygnus.com> 1998-09-17 Andrew MacLeod <amacleod@cygnus.com>
* exception.cc (__cplus_type_matcher): realign some code. * exception.cc (__cplus_type_matcher): realign some code.
......
...@@ -1910,15 +1910,22 @@ static void ...@@ -1910,15 +1910,22 @@ static void
maybe_warn_about_overly_private_class (t) maybe_warn_about_overly_private_class (t)
tree t; tree t;
{ {
if (warn_ctor_dtor_privacy int has_member_fn = 0;
int has_nonprivate_method = 0;
tree fn;
if (!warn_ctor_dtor_privacy
/* If the class has friends, those entities might create and /* If the class has friends, those entities might create and
access instances, so we should not warn. */ access instances, so we should not warn. */
&& !(CLASSTYPE_FRIEND_CLASSES (t) || (CLASSTYPE_FRIEND_CLASSES (t)
|| DECL_FRIENDLIST (TYPE_MAIN_DECL (t))) || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
/* We will have warned when the template was declared; there's /* We will have warned when the template was declared; there's
no need to warn on every instantiation. */ no need to warn on every instantiation. */
&& !CLASSTYPE_TEMPLATE_INSTANTIATION (t)) || CLASSTYPE_TEMPLATE_INSTANTIATION (t))
{ /* There's no reason to even consider warning about this
class. */
return;
/* We only issue one warning, if more than one applies, because /* We only issue one warning, if more than one applies, because
otherwise, on code like: otherwise, on code like:
...@@ -1931,17 +1938,13 @@ maybe_warn_about_overly_private_class (t) ...@@ -1931,17 +1938,13 @@ maybe_warn_about_overly_private_class (t)
we warn several times about essentially the same problem. */ we warn several times about essentially the same problem. */
int has_member_fn = 0;
int has_nonprivate_method = 0;
tree fn;
/* Check to see if all (non-constructor, non-destructor) member /* Check to see if all (non-constructor, non-destructor) member
functions are private. (Since there are no friends or functions are private. (Since there are no friends or
non-private statics, we can't ever call any of the private non-private statics, we can't ever call any of the private member
member functions.) */ functions.) */
for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn)) for (fn = TYPE_METHODS (t); fn; fn = TREE_CHAIN (fn))
/* We're not interested in compiler-generated methods; they /* We're not interested in compiler-generated methods; they don't
don't provide any way to call private members. */ provide any way to call private members. */
if (!DECL_ARTIFICIAL (fn)) if (!DECL_ARTIFICIAL (fn))
{ {
if (!TREE_PRIVATE (fn)) if (!TREE_PRIVATE (fn))
...@@ -1978,10 +1981,9 @@ maybe_warn_about_overly_private_class (t) ...@@ -1978,10 +1981,9 @@ maybe_warn_about_overly_private_class (t)
} }
} }
/* Even if some of the member functions are non-private, the /* Even if some of the member functions are non-private, the class
class won't be useful for much if all the constructors or won't be useful for much if all the constructors or destructors
destructors are private: such an object can never be created are private: such an object can never be created or destroyed. */
or destroyed. */
if (TYPE_HAS_DESTRUCTOR (t)) if (TYPE_HAS_DESTRUCTOR (t))
{ {
tree dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1); tree dtor = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (t), 1);
...@@ -2005,7 +2007,9 @@ maybe_warn_about_overly_private_class (t) ...@@ -2005,7 +2007,9 @@ maybe_warn_about_overly_private_class (t)
template <class T> class C { private: C(); }; template <class T> class C { private: C(); };
To avoid this asymmetry, we check TYPE_HAS_INIT_REF. */ To avoid this asymmetry, we check TYPE_HAS_INIT_REF. All
complete non-template or fully instantiated classes have this
flag set. */
if (!TYPE_HAS_INIT_REF (t)) if (!TYPE_HAS_INIT_REF (t))
nonprivate_ctor = 1; nonprivate_ctor = 1;
else else
...@@ -2034,7 +2038,6 @@ maybe_warn_about_overly_private_class (t) ...@@ -2034,7 +2038,6 @@ maybe_warn_about_overly_private_class (t)
return; return;
} }
} }
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment