Skip to content

Commit

Permalink
add [[nodiscard]] attribute via clang-tidy
Browse files Browse the repository at this point in the history
ran
run-clang-tidy-14.py -header-filter='.*' -checks='-*,modernize-use-nodiscard' -fix
under linux with most part of our code covered

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
  • Loading branch information
mgallien committed Oct 4, 2022
1 parent 5fc0175 commit 565a5f0
Show file tree
Hide file tree
Showing 127 changed files with 684 additions and 684 deletions.
14 changes: 7 additions & 7 deletions shell_integration/dolphin/ownclouddolphinpluginhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ class OWNCLOUDDOLPHINPLUGINHELPER_EXPORT OwncloudDolphinPluginHelper : public QO
public:
static OwncloudDolphinPluginHelper *instance();

bool isConnected() const;
[[nodiscard]] bool isConnected() const;
void sendCommand(const char *data);
QVector<QString> paths() const { return _paths; }
[[nodiscard]] QVector<QString> paths() const { return _paths; }

QString contextMenuTitle() const
[[nodiscard]] QString contextMenuTitle() const
{
return _strings.value("CONTEXT_MENU_TITLE", APPLICATION_NAME);
}
QString shareActionTitle() const
[[nodiscard]] QString shareActionTitle() const
{
return _strings.value("SHARE_MENU_TITLE", "Share …");
}
QString contextMenuIconName() const
[[nodiscard]] QString contextMenuIconName() const
{
return _strings.value("CONTEXT_MENU_ICON", APPLICATION_ICON_NAME);
}

QString copyPrivateLinkTitle() const { return _strings["COPY_PRIVATE_LINK_MENU_TITLE"]; }
QString emailPrivateLinkTitle() const { return _strings["EMAIL_PRIVATE_LINK_MENU_TITLE"]; }
[[nodiscard]] QString copyPrivateLinkTitle() const { return _strings["COPY_PRIVATE_LINK_MENU_TITLE"]; }
[[nodiscard]] QString emailPrivateLinkTitle() const { return _strings["EMAIL_PRIVATE_LINK_MENU_TITLE"]; }

QByteArray version() { return _version; }

Expand Down
12 changes: 6 additions & 6 deletions src/3rdparty/QProgressIndicator/QProgressIndicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,27 @@ class QProgressIndicator : public QWidget
\return The number of milliseconds between animation steps. By default, the animation delay is set to 40 milliseconds.
\sa setAnimationDelay
*/
int animationDelay() const { return m_delay; }
[[nodiscard]] int animationDelay() const { return m_delay; }

/*! Returns a Boolean value indicating whether the component is currently animated.
\return Animation state.
\sa startAnimation stopAnimation
*/
bool isAnimated () const;
[[nodiscard]] bool isAnimated () const;

/*! Returns a Boolean value indicating whether the receiver shows itself even when it is not animating.
\return Return true if the progress indicator shows itself even when it is not animating. By default, it returns false.
\sa setDisplayedWhenStopped
*/
bool isDisplayedWhenStopped() const;
[[nodiscard]] bool isDisplayedWhenStopped() const;

/*! Returns the color of the component.
\sa setColor
*/
const QColor & color() const { return m_color; }
[[nodiscard]] const QColor & color() const { return m_color; }

QSize sizeHint() const override;
int heightForWidth(int w) const override;
[[nodiscard]] QSize sizeHint() const override;
[[nodiscard]] int heightForWidth(int w) const override;
public slots:
/*! Starts the spin animation.
\sa stopAnimation isAnimated
Expand Down
16 changes: 8 additions & 8 deletions src/3rdparty/kirigami/wheelhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ class KirigamiWheelEvent : public QObject

void initializeFromEvent(QWheelEvent *event);

qreal x() const;
qreal y() const;
QPointF angleDelta() const;
QPointF pixelDelta() const;
int buttons() const;
int modifiers() const;
bool inverted() const;
[[nodiscard]] qreal x() const;
[[nodiscard]] qreal y() const;
[[nodiscard]] QPointF angleDelta() const;
[[nodiscard]] QPointF pixelDelta() const;
[[nodiscard]] int buttons() const;
[[nodiscard]] int modifiers() const;
[[nodiscard]] bool inverted() const;
bool isAccepted();
void setAccepted(bool accepted);

Expand Down Expand Up @@ -192,7 +192,7 @@ class WheelHandler : public QObject
explicit WheelHandler(QObject *parent = nullptr);
~WheelHandler() override;

QQuickItem *target() const;
[[nodiscard]] QQuickItem *target() const;
void setTarget(QQuickItem *target);

Q_SIGNALS:
Expand Down
2 changes: 1 addition & 1 deletion src/3rdparty/kmessagewidget/kmessagewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class KMessageWidgetPrivate
void slotTimeLineChanged(qreal);
void slotTimeLineFinished();

int bestContentHeight() const;
[[nodiscard]] int bestContentHeight() const;
};

void KMessageWidgetPrivate::init(KMessageWidget *q_ptr)
Expand Down
20 changes: 10 additions & 10 deletions src/3rdparty/kmessagewidget/kmessagewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class KMessageWidget : public QFrame
* Get the text of this message widget.
* @see setText()
*/
QString text() const;
[[nodiscard]] QString text() const;

/**
* Check whether word wrap is enabled.
Expand All @@ -149,22 +149,22 @@ class KMessageWidget : public QFrame
*
* @see setWordWrap()
*/
bool wordWrap() const;
[[nodiscard]] bool wordWrap() const;

/**
* Check whether the close button is visible.
*
* @see setCloseButtonVisible()
*/
bool isCloseButtonVisible() const;
[[nodiscard]] bool isCloseButtonVisible() const;

/**
* Get the type of this message.
* By default, the type is set to KMessageWidget::Information.
*
* @see KMessageWidget::MessageType, setMessageType()
*/
MessageType messageType() const;
[[nodiscard]] MessageType messageType() const;

/**
* Add @p action to the message widget.
Expand All @@ -187,24 +187,24 @@ class KMessageWidget : public QFrame
/**
* Returns the preferred size of the message widget.
*/
QSize sizeHint() const override;
[[nodiscard]] QSize sizeHint() const override;

/**
* Returns the minimum size of the message widget.
*/
QSize minimumSizeHint() const override;
[[nodiscard]] QSize minimumSizeHint() const override;

/**
* Returns the required height for @p width.
* @param width the width in pixels
*/
int heightForWidth(int width) const override;
[[nodiscard]] int heightForWidth(int width) const override;

/**
* The icon shown on the left of the text. By default, no icon is shown.
* @since 4.11
*/
QIcon icon() const;
[[nodiscard]] QIcon icon() const;

/**
* Check whether the hide animation started by calling animatedHide()
Expand All @@ -214,7 +214,7 @@ class KMessageWidget : public QFrame
* @see animatedHide(), hideAnimationFinished()
* @since 5.0
*/
bool isHideAnimationRunning() const;
[[nodiscard]] bool isHideAnimationRunning() const;

/**
* Check whether the show animation started by calling animatedShow()
Expand All @@ -224,7 +224,7 @@ class KMessageWidget : public QFrame
* @see animatedShow(), showAnimationFinished()
* @since 5.0
*/
bool isShowAnimationRunning() const;
[[nodiscard]] bool isShowAnimationRunning() const;

public Q_SLOTS:
/**
Expand Down
4 changes: 2 additions & 2 deletions src/3rdparty/qtlockedfile/qtlockedfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class QT_QTLOCKEDFILE_EXPORT QtLockedFile : public QFile

bool lock(LockMode mode, bool block = true);
bool unlock();
bool isLocked() const;
LockMode lockMode() const;
[[nodiscard]] bool isLocked() const;
[[nodiscard]] LockMode lockMode() const;

private:
#ifdef Q_OS_WIN
Expand Down
8 changes: 4 additions & 4 deletions src/3rdparty/qtokenizer/qtokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ struct QTokenizerPrivate {
{
}

bool isDelimiter(char_type c) const {
[[nodiscard]] bool isDelimiter(char_type c) const {
return delimiters.contains(c);
}

bool isQuote(char_type c) const {
[[nodiscard]] bool isQuote(char_type c) const {
return quotes.contains(c);
}

Expand Down Expand Up @@ -212,14 +212,14 @@ class QTokenizer {
Returns true if the current token is a delimiter,
if one more more delimiting characters have been set.
*/
bool isDelimiter() const { return d->isDelim; }
[[nodiscard]] bool isDelimiter() const { return d->isDelim; }

/*!
Returns the current token.
Use \c hasNext() to fetch the next token.
*/
T next() const {
[[nodiscard]] T next() const {
int len = std::distance(d->tokenBegin, d->tokenEnd);
const_iterator tmpStart = d->tokenBegin;
if (!d->returnQuotes && len > 1 && d->isQuote(*d->tokenBegin)) {
Expand Down
2 changes: 1 addition & 1 deletion src/3rdparty/qtsingleapplication/qtlocalpeer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class QtLocalPeer : public QObject
explicit QtLocalPeer(QObject *parent = nullptr, const QString &appId = QString());
bool isClient();
bool sendMessage(const QString &message, int timeout, bool block);
QString applicationId() const
[[nodiscard]] QString applicationId() const
{ return id; }
static QString appSessionId(const QString &appId);

Expand Down
4 changes: 2 additions & 2 deletions src/3rdparty/qtsingleapplication/qtsingleapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class QtSingleApplication : public QApplication
bool isRunning(qint64 pid = -1);

void setActivationWindow(QWidget* aw, bool activateOnMessage = true);
QWidget* activationWindow() const;
[[nodiscard]] QWidget* activationWindow() const;

QString applicationId() const;
[[nodiscard]] QString applicationId() const;
void setBlock(bool value);

public Q_SLOTS:
Expand Down
2 changes: 1 addition & 1 deletion src/3rdparty/qtsingleapplication/qtsinglecoreapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class QtSingleCoreApplication : public QCoreApplication
QtSingleCoreApplication(const QString &id, int &argc, char **argv);

bool isRunning();
QString id() const;
[[nodiscard]] QString id() const;
void setBlock(bool value);

public Q_SLOTS:
Expand Down
4 changes: 2 additions & 2 deletions src/common/checksums.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ class OCSYNC_EXPORT ValidateChecksumHeader : public QObject
*/
void start(std::unique_ptr<QIODevice> device, const QByteArray &checksumHeader);

QByteArray calculatedChecksumType() const;
QByteArray calculatedChecksum() const;
[[nodiscard]] QByteArray calculatedChecksumType() const;
[[nodiscard]] QByteArray calculatedChecksum() const;

signals:
void validated(const QByteArray &checksumType, const QByteArray &checksum);
Expand Down
8 changes: 4 additions & 4 deletions src/common/ownsql.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class OCSYNC_EXPORT SqlDatabase
bool transaction();
bool commit();
void close();
QString error() const;
[[nodiscard]] QString error() const;
sqlite3 *sqliteDb();

private:
Expand Down Expand Up @@ -111,8 +111,8 @@ class OCSYNC_EXPORT SqlQuery
int prepare(const QByteArray &sql, bool allow_failure = false);

~SqlQuery();
QString error() const;
int errorId() const;
[[nodiscard]] QString error() const;
[[nodiscard]] int errorId() const;

/// Checks whether the value at the given column index is NULL
bool nullValue(int index);
Expand Down Expand Up @@ -152,7 +152,7 @@ class OCSYNC_EXPORT SqlQuery
bindValueInternal(pos, value);
}

const QByteArray &lastQuery() const;
[[nodiscard]] const QByteArray &lastQuery() const;
int numRowsAffected();
void reset_and_clear_bindings();

Expand Down
8 changes: 4 additions & 4 deletions src/common/remotepermissions.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,18 @@ class OCSYNC_EXPORT RemotePermissions
RemotePermissions() = default;

/// array with one character per permission, "" is null, " " is non-null but empty
QByteArray toDbValue() const;
[[nodiscard]] QByteArray toDbValue() const;

/// output for display purposes, no defined format (same as toDbValue in practice)
QString toString() const;
[[nodiscard]] QString toString() const;

/// read value that was written with toDbValue()
static RemotePermissions fromDbValue(const QByteArray &);

/// read a permissions string received from the server, never null
static RemotePermissions fromServerString(const QString &);

bool hasPermission(Permissions p) const
[[nodiscard]] bool hasPermission(Permissions p) const
{
return _value & (1 << static_cast<int>(p));
}
Expand All @@ -87,7 +87,7 @@ class OCSYNC_EXPORT RemotePermissions
_value &= ~(1 << static_cast<int>(p));
}

bool isNull() const { return !(_value & notNullMask); }
[[nodiscard]] bool isNull() const { return !(_value & notNullMask); }
friend bool operator==(RemotePermissions a, RemotePermissions b)
{
return a._value == b._value;
Expand Down
6 changes: 3 additions & 3 deletions src/common/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ class Result
return &_result;
}

const T &get() const
[[nodiscard]] const T &get() const
{
ASSERT(!_isError)
return _result;
}

const Error &error() const &
[[nodiscard]] const Error &error() const &
{
ASSERT(_isError);
return _error;
Expand All @@ -134,7 +134,7 @@ class Result
return std::move(_error);
}

bool isValid() const { return !_isError; }
[[nodiscard]] bool isValid() const { return !_isError; }
};

namespace detail {
Expand Down
6 changes: 3 additions & 3 deletions src/common/syncfilestatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class OCSYNC_EXPORT SyncFileStatus
SyncFileStatus(SyncFileStatusTag);

void set(SyncFileStatusTag tag);
SyncFileStatusTag tag() const;
[[nodiscard]] SyncFileStatusTag tag() const;

void setShared(bool isShared);
bool shared() const;
[[nodiscard]] bool shared() const;

QString toSocketAPIString() const;
[[nodiscard]] QString toSocketAPIString() const;

private:
SyncFileStatusTag _tag = StatusNone;
Expand Down
4 changes: 2 additions & 2 deletions src/common/syncjournaldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
bool exists();
void walCheckpoint();

QString databaseFilePath() const;
[[nodiscard]] QString databaseFilePath() const;

static qint64 getPHash(const QByteArray &);

Expand Down Expand Up @@ -124,7 +124,7 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
* (As opposed to a small file transfer which is stored in the db so we can detect the case
* when the upload succeeded, but the connection was dropped before we got the answer)
*/
bool isChunked() const { return _transferid != 0; }
[[nodiscard]] bool isChunked() const { return _transferid != 0; }
};

struct PollInfo
Expand Down
Loading

0 comments on commit 565a5f0

Please sign in to comment.