]> granicus.if.org Git - clang/commit
Suggestions to fix -Wmissing-{prototypes,variable-declarations}
authorAaron Puchert <aaron.puchert@sap.com>
Tue, 18 Jun 2019 22:57:08 +0000 (22:57 +0000)
committerAaron Puchert <aaron.puchert@sap.com>
Tue, 18 Jun 2019 22:57:08 +0000 (22:57 +0000)
commit3d4f3f8617a779371e1fd86356e64f47dfa851e6
treed946b0956e5bf909eeb3d3e34a2d23dac03d208c
parentd57a5599710b94aea88703c2b543bf374f7ce4f5
Suggestions to fix -Wmissing-{prototypes,variable-declarations}

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.

We can't provide a fix-it hint for variable declarations, because
multiple VarDecls can share the same type, and if we put static in front
of that, we affect all declared variables, some of which might have
previous declarations.

We also provide no fix-it hint for the rare case of an `extern` function
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 FunctionDecl. I believe this information is only available earlier in
the AST construction from DeclSpec::getStorageClassSpecLoc(), but we
don't have that here.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D59402

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363749 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/Sema/warn-missing-prototypes.c
test/Sema/warn-missing-variable-declarations.c
test/SemaCXX/warn-missing-prototypes.cpp
test/SemaCXX/warn-missing-variable-declarations.cpp
test/SemaOpenCL/warn-missing-prototypes.cl