Page MenuHomePhabricator

Show note for -Wmissing-prototypes for functions with parameters
ClosedPublic

Authored by aaronpuchert on May 31 2019, 1:59 PM.

Details

Summary

There was a search for non-prototype declarations for the function, but
we only showed the results for zero-parameter functions. Now we show the
note for functions with parameters as well, but we omit the fix-it hint
suggesting to add void.

Diff Detail

Repository
rL LLVM

Event Timeline

aaronpuchert created this revision.May 31 2019, 1:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2019, 1:59 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Add checks that we don't emit the fix-it when we shouldn't.

aaron.ballman accepted this revision.Jun 17 2019, 10:42 AM

LGTM!

lib/Sema/SemaDecl.cpp
13335 ↗(On Diff #204171)

In this case, we could probably generate the parameter declarations for the user still, couldn't we? e.g.,

int f(); // We could insert "int i, int j" here as the fixit
int g(); // Just like we try to suggest "void" here already

int f(int i, int j) { return i + j; }
int g(void) { return 12; }

That could be done in a follow-up patch though.

This revision is now accepted and ready to land.Jun 17 2019, 10:42 AM
aaronpuchert added inline comments.Jun 17 2019, 11:58 AM
lib/Sema/SemaDecl.cpp
13335 ↗(On Diff #204171)

One difficulty might be that certain types used in the parameter list of the definition aren't available where the declaration is, like

int f();

struct X { int n; };
int f(struct X *x) { return x->n;}

So I'm not sure we can always do it, but sometimes perhaps.

aaron.ballman added inline comments.Jun 17 2019, 12:07 PM
lib/Sema/SemaDecl.cpp
13335 ↗(On Diff #204171)

That's a good point and reason enough to not try for it in this version of the patch (if at all).

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 18 2019, 3:49 PM