File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -238,9 +238,12 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
238
238
? MemberCallObject
239
239
: (Pointee ? Pointee : Result.Nodes .getNodeAs <Expr>(" STLObject" ));
240
240
FixItHint Hint;
241
- std::string ReplacementText = std::string (
242
- Lexer::getSourceText (CharSourceRange::getTokenRange (E->getSourceRange ()),
243
- *Result.SourceManager , getLangOpts ()));
241
+ std::string ReplacementText =
242
+ E->isImplicitCXXThis ()
243
+ ? " "
244
+ : std::string (Lexer::getSourceText (
245
+ CharSourceRange::getTokenRange (E->getSourceRange ()),
246
+ *Result.SourceManager , getLangOpts ()));
244
247
const auto *OpCallExpr = dyn_cast<CXXOperatorCallExpr>(E);
245
248
if (isBinaryOrTernary (E) || isa<UnaryOperator>(E) ||
246
249
(OpCallExpr && (OpCallExpr->getOperator () == OO_Star))) {
@@ -251,6 +254,8 @@ void ContainerSizeEmptyCheck::check(const MatchFinder::MatchResult &Result) {
251
254
// This can happen if the object is a smart pointer. Don't add anything
252
255
// because a '->' is already there (PR#51776), just call the method.
253
256
ReplacementText += " empty()" ;
257
+ } else if (E->isImplicitCXXThis ()) {
258
+ ReplacementText += " empty()" ;
254
259
} else if (E->getType ()->isPointerType ())
255
260
ReplacementText += " ->empty()" ;
256
261
else
Original file line number Diff line number Diff line change @@ -186,6 +186,10 @@ Changes in existing checks
186
186
<clang-tidy/checks/portability/template-virtual-member-function>` check to
187
187
avoid false positives on pure virtual member functions.
188
188
189
+ - Improved :doc: `readability-container-size-empty
190
+ <clang-tidy/checks/readability/container-size-empty>` check by correctly
191
+ generating fix-it hints when size method is called from implicit ``this ``.
192
+
189
193
- Improved :doc: `readability-identifier-naming
190
194
<clang-tidy/checks/readability/identifier-naming>` check by ignoring
191
195
declarations in system headers.
Original file line number Diff line number Diff line change @@ -895,3 +895,16 @@ namespace PR94454 {
895
895
int operator " " _ci() { return 0 ; }
896
896
auto eq = 0_ci == 0 ;
897
897
}
898
+
899
+ namespace GH152387 {
900
+
901
+ class foo : public std ::string{
902
+ void doit () {
903
+ if (!size ()) {
904
+ // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: the 'empty' method should be used to check for emptiness instead of 'size'
905
+ // CHECK-FIXES: if (empty()) {
906
+ }
907
+ }
908
+ };
909
+
910
+ }
You can’t perform that action at this time.
0 commit comments