[clang-tools-extra] r265671 - [clang-tidy] Fix FP with readability-redundant-string-init for default arguments

Etienne Bergeron via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 7 07:18:54 PDT 2016


Author: etienneb
Date: Thu Apr  7 09:18:53 2016
New Revision: 265671

URL: http://llvm.org/viewvc/llvm-project?rev=265671&view=rev
Log:
[clang-tidy] Fix FP with readability-redundant-string-init for default 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

Modified:
    clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/readability-redundant-string-init.cpp

Modified: clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp?rev=265671&r1=265670&r2=265671&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/readability/RedundantStringInitCheck.cpp Thu Apr  7 09:18:53 2016
@@ -61,7 +61,8 @@ void RedundantStringInitCheck::registerM
                         hasInitializer(
                             expr(anyOf(EmptyStringCtorExpr,
                                        EmptyStringCtorExprWithTemporaries))
-                            .bind("expr"))))
+                            .bind("expr"))),
+                unless(parmVarDecl()))
           .bind("decl"),
       this);
 }

Modified: clang-tools-extra/trunk/test/clang-tidy/readability-redundant-string-init.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-redundant-string-init.cpp?rev=265671&r1=265670&r2=265671&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/readability-redundant-string-init.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-redundant-string-init.cpp Thu Apr  7 09:18:53 2016
@@ -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 = "") {}
+




More information about the cfe-commits mailing list