diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 51f276c65..32ab74b9c 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2887,7 +2887,8 @@ void CheckOther::checkRedundantCopy() if (fScope && fScope->bodyEnd && Token::Match(fScope->bodyEnd->tokAt(-3), "return %var% ;")) { const Token* varTok = fScope->bodyEnd->tokAt(-2); if (varTok->variable() && !varTok->variable()->isGlobal() && - (!varTok->variable()->type() || estimateSize(varTok->variable()->type(), mSettings, symbolDatabase) > 2 * mSettings->platform.sizeof_pointer)) + (!varTok->variable()->type() || !varTok->variable()->type()->classScope || + estimateSize(varTok->variable()->type(), mSettings, symbolDatabase) > 2 * mSettings->platform.sizeof_pointer)) redundantCopyError(startTok, startTok->str()); } } diff --git a/test/cfg/qt.cpp b/test/cfg/qt.cpp index 73650f09c..63ccf3b1d 100644 --- a/test/cfg/qt.cpp +++ b/test/cfg/qt.cpp @@ -580,3 +580,16 @@ namespace { Q_PROPERTY(QHash hash READ hash WRITE setHash) }; } + +struct SEstimateSize { + inline const QString& get() const { return m; } + QString m; +}; + +class QString; + +void dontCrashEstimateSize(const SEstimateSize& s) { + // cppcheck-suppress redundantCopyLocalConst + QString q = s.get(); + if (!q.isNull()) {} +}