summaryrefslogtreecommitdiff
path: root/compilerplugins/clang
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-01-31 13:24:13 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-02-01 07:57:16 +0000
commitdce867e8c4863c969eea3515a988630b74708a43 (patch)
tree340cb8408241fe34bf1c76f54b9ca41ca95a72ab /compilerplugins/clang
parent27832947f0d9406c1757182ffa57262f3f03af4b (diff)
loplugin:stringconstant handle calls to constructors with one arg
Change-Id: Ide9148a908bef46ba14640dfa6f556beaf6e3f60 Reviewed-on: https://gerrit.libreoffice.org/33772 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins/clang')
-rw-r--r--compilerplugins/clang/stringconstant.cxx11
-rw-r--r--compilerplugins/clang/test/stringconstant.cxx3
2 files changed, 13 insertions, 1 deletions
diff --git a/compilerplugins/clang/stringconstant.cxx b/compilerplugins/clang/stringconstant.cxx
index 3238246125c5..9ae672ae9050 100644
--- a/compilerplugins/clang/stringconstant.cxx
+++ b/compilerplugins/clang/stringconstant.cxx
@@ -66,6 +66,10 @@ bool hasOverloads(FunctionDecl const * decl, unsigned arguments) {
if (f != nullptr && f->getMinRequiredArguments() <= arguments
&& f->getNumParams() >= arguments)
{
+ auto consDecl = dyn_cast<CXXConstructorDecl>(f);
+ if (consDecl && consDecl->isCopyConstructor()) {
+ break;
+ }
++n;
if (n == 2) {
return true;
@@ -1058,12 +1062,17 @@ bool StringConstant::VisitCXXConstructExpr(CXXConstructExpr const * expr) {
return true;
}
- std::string file(compiler.getSourceManager().getFilename(
+ StringRef file(compiler.getSourceManager().getFilename(
compiler.getSourceManager().getSpellingLoc(expr->getLocStart())));
if (file == SRCDIR "/sal/qa/rtl/oustringbuffer/test_oustringbuffer_tostring.cxx")
{
return true;
}
+ // there is some template magic here I don't know how to work around
+ if (file.startswith(SRCDIR "/connectivity"))
+ {
+ return true;
+ }
if (isInUnoIncludeFile(expr->getLocStart())) {
return true;
}
diff --git a/compilerplugins/clang/test/stringconstant.cxx b/compilerplugins/clang/test/stringconstant.cxx
index f2cf48c602a7..392567fa3cab 100644
--- a/compilerplugins/clang/test/stringconstant.cxx
+++ b/compilerplugins/clang/test/stringconstant.cxx
@@ -18,6 +18,7 @@ extern void foo(OUString const &); // expected-error {{extern prototype in main
struct Foo {
Foo(OUString const &, int) {}
+ Foo(OUString const &) {}
};
int main() {
@@ -57,6 +58,8 @@ int main() {
foo(OUString("xxx")); // expected-error {{in call of 'foo', replace 'OUString' constructed from a string literal directly with the string literal [loplugin:stringconstant}}
Foo aFoo(OUString("xxx"), 1); // expected-error {{in call of 'Foo::Foo', replace 'OUString' constructed from a string literal directly with the string literal}}
(void)aFoo;
+ Foo aFoo2(OUString("xxx")); // expected-error {{in call of 'Foo::Foo', replace 'OUString' constructed from a string literal directly with the string literal}}
+ (void)aFoo2;
}