Skip to content
Commit e43c18c5 authored by Igor Kushnir's avatar Igor Kushnir
Browse files

cmake: return QDebug by value from operator<< overloads

Replacing `return debug.maybeSpace();` with `return debug;` in these two
operators' definitions triggers the following parser problem:
    Problem in Semantic analysis
    Location: cmakeprojectdata.h :49
    Reference to stack memory associated with parameter 'debug' returned [-Wreturn-stack-address]

QDebug::maybeSpace() returns a reference to the QDebug object, on which
it is called, so the issue is present in any case, even if the parser
doesn't detect it.

Qt 5 and Qt 6 documentation examples, e.g.
    https://doc.qt.io/qt-5/custom-types.html#making-the-type-printable
take and return QDebug by value.

Taking and returning QDebug by reference does not compile if the
operator<< overload for the previous printed object returns QDebug by
value (the QVector's overload for instance):
kdevelop/plugins/cmake/cmakeserverimportjob.cpp:77:56: error: cannot bind non-const lvalue reference of type ‘QDebug&’ to an rvalue of type ‘QDebug’
   77 |                     qCDebug(CMAKE) << "registering..." << sources << file;
      |                                                        ^
parent 14e9bb38
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment