Skip to content

Commit

Permalink
[clang-tidy] Fix FP with readability-redundant-string-init for defaul…
Browse files Browse the repository at this point in the history
…t arguments

Summary:
Clang-tidy is reporting a warning of redundant string initialisation
on a string parameter initialized with empty string.

See bug: 27087

The reported example is:
```
#include <string>
void fn(std::string a = "");
```

Reviewers: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D18829

llvm-svn: 265671
  • Loading branch information
bergeret committed Apr 7, 2016
1 parent e23b6de commit f6660da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -61,7 +61,8 @@ void RedundantStringInitCheck::registerMatchers(MatchFinder *Finder) {
hasInitializer(
expr(anyOf(EmptyStringCtorExpr,
EmptyStringCtorExprWithTemporaries))
.bind("expr"))))
.bind("expr"))),
unless(parmVarDecl()))
.bind("decl"),
this);
}
Expand Down
Expand Up @@ -131,3 +131,10 @@ void k() {

std::string d = "u", e = "u", f = "u";
}

// These cases should not generate warnings.
extern void Param1(std::string param = "");
extern void Param2(const std::string& param = "");
void Param3(std::string param = "") {}
void Param4(STRING param = "") {}

0 comments on commit f6660da

Please sign in to comment.