[Libreoffice-commits] core.git: compilerplugins/clang
Stephan Bergmann
sbergman at redhat.com
Wed Dec 6 10:38:33 UTC 2017
compilerplugins/clang/passstuffbyref.cxx | 7 +++++--
compilerplugins/clang/test/passstuffbyref.cxx | 7 +++++++
2 files changed, 12 insertions(+), 2 deletions(-)
New commits:
commit 37fe0f729c17bd30d9f273b268b15c353c34a156
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Tue Dec 5 23:00:58 2017 +0100
Better heuristic to only look through implicit copy/move ctors
At least recent libc++ has a std::string ctor overload without a (defaulted)
Allocator argument (which otherwise causes creation of a temporary Allocator
object and thus a ExprWithCleanups), so in C++17 mode (i.e., with no implicit
move CXXConstructExpr -> MaterializeTemporaryExpr -> CXXBindTemporaryExpr chain
in the way) CellInfo::toString (sw/source/filter/ww8/WW8TableInfo.cxx) has a
ReturnStmt of just
> ReturnStmt
> `-ImplicitCastExpr 'std::string':'class std::__1::basic_string<char>' <ConstructorConversion>
> `-CXXConstructExpr 'std::string':'class std::__1::basic_string<char>' 'void (const char *)'
> `-ImplicitCastExpr 'const char *' <NoOp>
> `-ImplicitCastExpr 'char *' <ArrayToPointerDecay>
> `-DeclRefExpr 'char [256]' lvalue Var 'sBuffer' 'char [256]'
that erroneously triggered loplugin:passstuffbyref.
Change-Id: I53c8911cb1356560692c003808280a103c399e25
Reviewed-on: https://gerrit.libreoffice.org/45916
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman at redhat.com>
diff --git a/compilerplugins/clang/passstuffbyref.cxx b/compilerplugins/clang/passstuffbyref.cxx
index f87e668ed4fa..3b4b974c697f 100644
--- a/compilerplugins/clang/passstuffbyref.cxx
+++ b/compilerplugins/clang/passstuffbyref.cxx
@@ -310,8 +310,11 @@ bool PassStuffByRef::isReturnExprDisqualified(const Expr* expr)
if (isa<ExprWithCleanups>(expr)) {
return true;
}
- if (const CXXConstructExpr* constructExpr = dyn_cast<CXXConstructExpr>(expr)) {
- if (constructExpr->getNumArgs()==1) {
+ if (const CXXConstructExpr* constructExpr = dyn_cast<CXXConstructExpr>(expr))
+ {
+ if (constructExpr->getNumArgs()==1
+ && constructExpr->getConstructor()->isCopyOrMoveConstructor())
+ {
expr = constructExpr->getArg(0)->IgnoreParenCasts();
}
}
diff --git a/compilerplugins/clang/test/passstuffbyref.cxx b/compilerplugins/clang/test/passstuffbyref.cxx
index 89f51fb1c294..2f076e58e7b7 100644
--- a/compilerplugins/clang/test/passstuffbyref.cxx
+++ b/compilerplugins/clang/test/passstuffbyref.cxx
@@ -26,6 +26,13 @@ void f()
s = new S(v1, v2);
}
+struct S2 { S2(int); };
+
+S2 f2() {
+ static int n;
+ return n;
+}
+
// expected-no-diagnostics
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
More information about the Libreoffice-commits
mailing list