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>
This commit is contained in:
parent
b23aec2266
commit
3d5c0a9453
2 changed files with 22 additions and 3 deletions
|
@ -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: */
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue