summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2024-02-02 10:49:14 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2024-02-02 20:40:58 +0100
commit3d5c0a94539d2196c7d0dd9f52660ba9e58d31b8 (patch)
treec9832717f9a019075a53a2eb8e7dd44981b6510e
parenttdf#159461 deadlock in Dialog "XML Filter Settings" (diff)
downloadcore-3d5c0a94539d2196c7d0dd9f52660ba9e58d31b8.tar.gz
core-3d5c0a94539d2196c7d0dd9f52660ba9e58d31b8.zip
loplugin:unnecessarygetstr fix false +
spotted in https://gerrit.libreoffice.org/c/core/+/162869 Change-Id: I87d9fdcfed5282f0e94fc8aa95a46054883fdd79 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162929 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--compilerplugins/clang/test/unnecessarygetstr.cxx7
-rw-r--r--compilerplugins/clang/unnecessarygetstr.cxx18
2 files changed, 22 insertions, 3 deletions
diff --git a/compilerplugins/clang/test/unnecessarygetstr.cxx b/compilerplugins/clang/test/unnecessarygetstr.cxx
index c0960557a89b..bdb58cde2ef7 100644
--- a/compilerplugins/clang/test/unnecessarygetstr.cxx
+++ b/compilerplugins/clang/test/unnecessarygetstr.cxx
@@ -10,6 +10,7 @@
#include <sal/config.h>
#include <ostream>
+#include <sstream>
#include <string_view>
#include <string>
@@ -128,4 +129,10 @@ void foo(const OString&);
void test(std::string v) { foo(v.c_str()); }
}
+// no warning expected
+namespace test7
+{
+void test(const OString& v) { std::stringstream aStream(v.getStr()); }
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/unnecessarygetstr.cxx b/compilerplugins/clang/unnecessarygetstr.cxx
index c80877a78554..589ab405f786 100644
--- a/compilerplugins/clang/unnecessarygetstr.cxx
+++ b/compilerplugins/clang/unnecessarygetstr.cxx
@@ -11,6 +11,7 @@
#include <cassert>
#include <stack>
+#include <unordered_set>
#include "check.hxx"
#include "plugin.hxx"
@@ -60,11 +61,20 @@ public:
if (ignoreLocation(constructExpr))
return true;
auto tc = loplugin::TypeCheck(constructExpr->getType());
- if (tc.ClassOrStruct("basic_string").StdNamespace())
+ if (tc.ClassOrStruct("basic_stringstream").StdNamespace())
+ {
+ // ignore the implicit-conversion nodes that are added here
+ if (constructExpr->getNumArgs() > 0)
+ nodesToIgnore.insert(constructExpr->getArg(0)->IgnoreImplicit());
+ }
+ else if (tc.ClassOrStruct("basic_string").StdNamespace())
{
if (constructExpr->getNumArgs() == 1 || constructExpr->getNumArgs() == 2)
- checkForGetStr(constructExpr->getArg(0), "string constructor",
- /*isOStringConstructor*/ false);
+ {
+ if (nodesToIgnore.find(constructExpr) == nodesToIgnore.end())
+ checkForGetStr(constructExpr->getArg(0), "string constructor",
+ /*isOStringConstructor*/ false);
+ }
}
else if (tc.ClassOrStruct("basic_string_view").StdNamespace())
{
@@ -138,6 +148,8 @@ private:
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
}
+
+ std::unordered_set<const Expr*> nodesToIgnore;
};
loplugin::Plugin::Registration<UnnecessaryGetStr> unnecessarygetstr("unnecessarygetstr");