This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ PATCH] Fix implicit assignment operators with anonymous aggregates
On Wed, Mar 21, 2001 at 04:09:17PM +0000, Jason Merrill wrote:
> >>>>> "Jakub" == Jakub Jelinek <jakub@redhat.com> writes:
>
> > + if (TREE_CODE (field) == FIELD_DECL)
> > + {
> > + type = TREE_TYPE (field);
> > + if (CLASS_TYPE_P (type) && TYPE_HAS_COMPLEX_ASSIGN_REF (type))
> > + cp_error_at ("member %#D' with copy assignment operator not allowed in anonymous aggregate", field);
> > + }
>
> Let's also check for copy ctor and destructor, while we're at it.
Ok. I haven't done it because at least the copy constructor was called by
gcc eventhough anonymous structure had no copy constructor.
>
> > /* Make sure that a declaration with no declarator is well-formed, i.e.
> > --- gcc/cp/typeck.c.jj Mon Mar 12 11:45:35 2001
> > +++ gcc/cp/typeck.c Wed Mar 21 11:41:50 2001
> > @@ -5596,6 +5596,11 @@ build_modify_expr (lhs, modifycode, rhs)
> > }
> > else if (modifycode == NOP_EXPR)
> > {
> > + /* Anonymous aggregates don't have any methods, so avoid calling
> > + them. */
> > + if (ANON_AGGR_TYPE_P (lhstype))
> > + return build (MODIFY_EXPR, lhstype, lhs, rhs);
> > +
> > /* `operator=' is not an inheritable operator. */
> > if (! IS_AGGR_TYPE (lhstype))
> > /* Do the default thing */;
>
> Is there a reason we shouldn't "Do the default thing" for anonymous
> aggregates? If so, maybe this logic belongs in do_build_assign_ref after
> all.
Yes, in fact that was what I tried first even before changing
do_build_assign_ref. Doing the default thing means convert_for_assignment
was called on the anon union, this calls perform_implicit_conversion -> convert_like_real
-> build_new_method_call and errors because the anonymous aggregate does not
have an copy constructor:
anon8.C:11: `A::<anonymous union>::._0(const A::<anonymous union>&)' is
inaccessible
Should I keep the change in build_modify_expr or use the previous patch plus
the decl.c bits to disallow ctors, dtors and assign_refs?
Jakub