[PATCH 0/4] Applying fix-its on behalf of the user to their code

Trevor Saunders tbsaunde@tbsaunde.org
Wed Aug 24 13:29:00 GMT 2016


On Wed, Aug 24, 2016 at 09:59:18AM +0200, Richard Biener wrote:
> On Wed, Aug 24, 2016 at 3:28 AM, David Malcolm <dmalcolm@redhat.com> wrote:
> > Currently our diagnostics subsystem can emit fix-it hints
> > suggesting edits the user can make to their code to fix warnings/errors,
> > but currently the user must make these edits manually [1].
> >
> > The following patch kit adds two command-line options with which
> > we can make the changes on behalf of the user:
> >
> > (A) -fdiagnostics-generate-patch emits a diff to stderr, which
> > could potentially be applied using "patch"; it also gives another
> > way to visualize the fix-its.
> >
> > (B) -fdiagnostics-apply-fixits, which writes back the changes
> > to the input files.
> 
> I don't like this very much - option (A) looks good with the user having
> to manually apply a patch.  But (B) is just asking for trouble ;)

 Obviously your work flow needs to deal with things other than your
 editor changing files for this to be useful, but it can only cause
 trouble for you if you ask for it.  I don't think it should be the
 default, and I'm not sure if all fix it hints are good candidates.
 However it does make my life better if I don't need to do busy work
 like insert |typename| to make the compiler happy with my template
 usage.

 I think the even better use of this is for plugins that want to rewrite
 the source code for a project to change some API's consumers in a
 mechanical way.  Currently you usually get to do that by manually
 applying the same fix whever the compiler tells you there is an error,
 and in some cases that really should be automatable.  I believe
 Libreoffice has used clang plugins to this to good effect, but I don't
 know any details.

> I'd rather have -fdiagnostics-apply-fixits apply the fixit hints for
> the current compilation only (so you'll see if the compile is successful
> after applying the suggestions).  That is, work more in a "error recovery"
> mode.

That might be useful too.

Trev



More information about the Gcc-patches mailing list