This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PATCH to avoid bogus warning
>>>>> Mark Mitchell <mark@markmitchell.com> writes:
> Well, it wasn't quite that simple. I bit the bullet and cleaned up
> the code to generate these warnings a bit, with the following patch,
> which also allowed localizing the warning code.
Great, thanks.
> ! if (warn_ctor_dtor_privacy
> ! /* If the class has friends, those entities might create and
> ! access instances, so we should not warn. */
> ! && !(CLASSTYPE_FRIEND_CLASSES (t)
> ! || DECL_FRIENDLIST (TYPE_MAIN_DECL (t)))
> ! /* We will have warned when the template was declared; there's
> ! no need to warn on every instantiation. */
> ! && !CLASSTYPE_TEMPLATE_INSTANTIATION (t))
> ! {
I generally prefer the
if (! interesting)
return;
style to
if (interesting)
{
/* big ol' block */;
}
and similarly for break in loops, to hold down the nesting level.
> ! for (i = 0; i < CLASSTYPE_N_BASECLASSES (t); i++)
> ! if (TREE_VIA_PUBLIC (TREE_VEC_ELT (binfos, i))
> ! || TREE_VIA_PROTECTED (TREE_VEC_ELT (binfos, i)))
> ! {
> ! has_nonprivate_method = 1;
> ! break;
> ! }
Seems odd that we would count a public base as suppressing this warning. I
wonder why that was there.
> ! /* If a non-template class does not define a copy
> ! constructor, one is defined for it, enabling it to avoid
> ! this warning. For a template class, this does not
> ! happen, and so we would normally get a warning on:
> !
> ! template <class T> class C { private: C(); };
> !
> ! To avoid this asymmetry, we check TYPE_HAS_INIT_REF. */
> ! if (!TYPE_HAS_INIT_REF (t))
> ! nonprivate_ctor = 1;
Perhaps the comment should clarify that TYPE_HAS_INIT_REF is always true
for a complete class these days.
Jason