File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
lib/StaticAnalyzer/Checkers/WebKit
test/Analysis/Checkers/WebKit Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -231,11 +231,9 @@ bool isSingleton(const FunctionDecl *F) {
231
231
if (!MethodDecl->isStatic ())
232
232
return false ;
233
233
}
234
- const auto &Name = safeGetName (F);
235
- std::string SingletonStr = " singleton" ;
236
- auto index = Name.find (SingletonStr);
237
- return index != std::string::npos &&
238
- index == Name.size () - SingletonStr.size ();
234
+ const auto &NameStr = safeGetName (F);
235
+ StringRef Name = NameStr; // FIXME: Make safeGetName return StringRef.
236
+ return Name == " singleton" || Name.ends_with (" Singleton" );
239
237
}
240
238
241
239
// We only care about statements so let's use the simple
Original file line number Diff line number Diff line change @@ -343,6 +343,12 @@ class RefCounted {
343
343
return s_RefCounted;
344
344
}
345
345
346
+ static RefCounted& otherSingleton () {
347
+ static RefCounted s_RefCounted;
348
+ s_RefCounted.ref ();
349
+ return s_RefCounted;
350
+ }
351
+
346
352
Number nonTrivial1 () { return Number (3 ) + Number (4 ); }
347
353
Number nonTrivial2 () { return Number { 0.3 }; }
348
354
int nonTrivial3 () { return v ? otherFunction () : 0 ; }
@@ -512,6 +518,8 @@ class UnrelatedClass {
512
518
513
519
RefCounted::singleton ().trivial18 (); // no-warning
514
520
RefCounted::singleton ().someFunction (); // no-warning
521
+ RefCounted::otherSingleton ().trivial18 (); // no-warning
522
+ RefCounted::otherSingleton ().someFunction (); // no-warning
515
523
516
524
getFieldTrivial ().recursiveTrivialFunction (7 ); // no-warning
517
525
getFieldTrivial ().recursiveComplexFunction (9 );
You can’t perform that action at this time.
0 commit comments