namespace {
+AST_MATCHER(VarDecl, isLocalVariable) {
+ return Node.isLocalVarDecl();
+}
+
FixItHint generateFixItHint(const VarDecl *Decl, bool IsConst) {
char FC = Decl->getName()[0];
if (!llvm::isAlpha(FC) || Decl->getName().size() == 1) {
// need to add two matchers since we need to bind different ids to distinguish
// constants and variables. Since bind() can only be called on node matchers,
// we cannot make it in one matcher.
+ //
+ // Note that hasGlobalStorage() matches static variables declared locally
+ // inside a function or method, so we need to exclude those with
+ // isLocalVariable().
Finder->addMatcher(
varDecl(hasGlobalStorage(), unless(hasType(isConstQualified())),
- unless(matchesName("::g[A-Z]")))
+ unless(isLocalVariable()), unless(matchesName("::g[A-Z]")))
.bind("global_var"),
this);
Finder->addMatcher(varDecl(hasGlobalStorage(), hasType(isConstQualified()),
+ unless(isLocalVariable()),
unless(matchesName("::k[A-Z]")))
.bind("global_const"),
this);
// CHECK-FIXES: static NSString* const k_Alpha = @"SecondNotAlpha";
static NSString* const kGood = @"hello";
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:24: warning: const global variable 'kGood' must have a name which starts with 'k[A-Z]' [google-objc-global-variable-declaration]
static NSString* gMyIntGood = 0;
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:18: warning: non-const global variable 'gMyIntGood' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
+
@implementation Foo
- (void)f {
int x = 0;
-// CHECK-MESSAGES-NOT: :[[@LINE-1]]:9: warning: non-const global variable 'gMyIntGood' must have a name which starts with 'g[A-Z]' [google-objc-global-variable-declaration]
+ static int bar;
+ static const int baz = 42;
}
@end