This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH to deal with trivial but non-callable [cd]tors
- From: Eric Botcazou <ebotcazou at adacore dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 30 Oct 2013 19:44:14 +0100
- Subject: Re: C++ PATCH to deal with trivial but non-callable [cd]tors
- Authentication-results: sourceware.org; auth=none
- References: <52680FD9 dot 7040302 at redhat dot com> <5471599 dot klPL436CBS at polaris> <5271317E dot 1010503 at redhat dot com>
> > +/* Return whether DECL, a method of a C++ TYPE, is trivial, that is to
> > say + doesn't do anything for the objects of TYPE. */
> > +
> > +static bool
> > +is_trivial_method (const_tree decl, const_tree type)
> > +{
> > + if (cpp_check (decl, IS_CONSTRUCTOR) && !TYPE_NEEDS_CONSTRUCTING
> > (type)) + return true;
>
> This will tell you whether decl is a constructor for a type with some
> non-trivial constructor, but not whether decl itself is non-trivial.
I think that's good enough though, in practice we only need to eliminate
constructors/destructors for POD types. As soon as there is one non-trivial
method, the game is essentially over.
> I think a good way to check for any non-trivial methods would be to
> check trivial_type_p in the front end and then see if there are any
> !DECL_ARTIFICIAL decls in TYPE_METHODS.
That sounds interesting indeed, thanks for the tip. I was initially reluctant
to call into the front-end because of side-effects, but the various predicates
in tree.c seem fine in this respect.
--
Eric Botcazou