mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 14:06:06 +00:00

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 llvm-svn: 363749
22 lines
1.0 KiB
C
22 lines
1.0 KiB
C
// RUN: %clang_cc1 -Wmissing-variable-declarations -fsyntax-only -verify %s
|
|
|
|
int vbad1; // expected-warning{{no previous extern declaration for non-static variable 'vbad1'}}
|
|
// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
|
|
|
|
int vbad2;
|
|
int vbad2 = 10; // expected-warning{{no previous extern declaration for non-static variable 'vbad2'}}
|
|
// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
|
|
|
|
struct { // expected-note{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
|
|
int mgood1;
|
|
} vbad3; // expected-warning{{no previous extern declaration for non-static variable 'vbad3'}}
|
|
|
|
int vbad4;
|
|
int vbad4 = 10; // expected-warning{{no previous extern declaration for non-static variable 'vbad4'}}
|
|
// expected-note@-1{{declare 'static' if the variable is not intended to be used outside of this translation unit}}
|
|
extern int vbad4;
|
|
|
|
extern int vgood1;
|
|
int vgood1;
|
|
int vgood1 = 10;
|