Page MenuHomePhabricator

Fix-it hints for -Wmissing-{prototypes,variable-declarations}
Needs ReviewPublic

Authored by aaronpuchert on Mar 14 2019, 7:13 PM.

Details

Summary

I've found that most often the proper way to fix this warning is to add
static, because if the code otherwise compiles and links, the function
or variable is apparently not needed outside of the TU.

There is no fix-it for the rare case of an "extern definition", because
that would require removing extern and I have no idea how to get the
source location of the storage class specifier from a VarDecl. I believe
this information is only available earlier in the AST construction from
DeclSpec::getStorageClassSpecLoc(), but we don't have that here.

Diff Detail

Event Timeline

aaronpuchert created this revision.Mar 14 2019, 7:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2019, 7:13 PM
aaronpuchert added inline comments.Mar 14 2019, 7:21 PM
test/Sema/warn-missing-prototypes.c
7

Maybe there shouldn't be a fix-it here, as there is a declaration, which is just not a prototype.

18–19

As I wrote in the commit message: this could be fixed by replacing extern with static, but I don't think we have the SourceLocation for the storage class specifier available where the warning is emitted. Maybe I'm overlooking something though.

Don't suggest adding static if there is a non-prototype declaration. This required a minor refactoring: we let ShouldWarnAboutMissingPrototype return any kind of declaration it finds and check for the number of parameters at the call site.

aaronpuchert marked an inline comment as done.Mar 16 2019, 9:44 AM