Cast to (void) type
-
Certain compilers would issue a warning on calling functions that are defined to return a value and then ignoring that return value. Casting the return value to void would tell the compiler (and anyone reading the code) that the discarding of it was intentional. So the compilation warning would go away.
Not sure whether any compilers still have this warning. At least some static code analysers do.
-
Will there be a normal practice to use code like this everywhere?
I found what Qt have macros Q_REQUIRED_RESULT, but it used only in 2 files:
- qimage.h
- qstring.h
And this work only for GCC. But i think this macros need add to methods wich return pointer to dynamic allocated object what must delete by user like:
@
class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
{
...
QNetworkReply *head(const QNetworkRequest &request;) Q_REQUIRED_RESULT;
QNetworkReply *get(const QNetworkRequest &request;) Q_REQUIRED_RESULT;
QNetworkReply *post(const QNetworkRequest &request;, QIODevice *data) Q_REQUIRED_RESULT;
QNetworkReply *post(const QNetworkRequest &request;, const QByteArray &data;) Q_REQUIRED_RESULT;
QNetworkReply *put(const QNetworkRequest &request;, QIODevice *data) Q_REQUIRED_RESULT;
QNetworkReply *put(const QNetworkRequest &request;, const QByteArray &data;) Q_REQUIRED_RESULT;
QNetworkReply *deleteResource(const QNetworkRequest &request;) Q_REQUIRED_RESULT;
@From QtAssistant:
bq. Note: After the request has finished, it is the responsibility of the user to delete the QNetworkReply object at an appropriate time.But there is a problem. (void) cast doesn't work anymore with this attribute.
2Web Community Manager: quotes and code syntax highlighter are broken (artefact ';' after argument of method) :`(