Skip to content

Commit a70c649

Browse files
committed
fixed -Wdeprecated-this-capture Clang C++20 warnings
example: ``` /home/user/CLionProjects/cppcheck/lib/pathmatch.cpp:37:37: warning: implicit capture of 'this' with a capture default of '=' is deprecated [-Wdeprecated-this-capture] 37 | return match(pattern, path, mBasepath, mode, mSyntax); | ^ /home/user/CLionProjects/cppcheck/lib/pathmatch.cpp:36:63: note: add an explicit capture of 'this' to capture '*this' by reference 36 | return std::any_of(mPatterns.cbegin(), mPatterns.cend(), [=] (const std::string &pattern) { | ^ | , this ```
1 parent 69a2d17 commit a70c649

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

gui/resultstree.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "applicationlist.h"
2323
#include "checkers.h"
2424
#include "common.h"
25+
#include "config.h"
2526
#include "erroritem.h"
2627
#include "errorlogger.h"
2728
#include "errortypes.h"
@@ -702,15 +703,15 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
702703
{
703704
auto *action = new QAction(tr("No tag"), tagMenu);
704705
tagMenu->addAction(action);
705-
connect(action, &QAction::triggered, [=]() {
706+
connect(action, &QAction::triggered, [EXPLICIT_THIS]() {
706707
tagSelectedItems(QString());
707708
});
708709
}
709710

710711
for (const QString& tagstr : currentProject->getTags()) {
711712
auto *action = new QAction(tagstr, tagMenu);
712713
tagMenu->addAction(action);
713-
connect(action, &QAction::triggered, [=]() {
714+
connect(action, &QAction::triggered, [EXPLICIT_THIS]() {
714715
tagSelectedItems(tagstr);
715716
});
716717
}

lib/config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@
131131
# define RET_NONNULL
132132
#endif
133133

134+
#if __cplusplus >= 202002L
135+
# define EXPLICIT_THIS =, this
136+
#else
137+
# define EXPLICIT_THIS =
138+
#endif
139+
134140
#define REQUIRES(msg, ...) class=typename std::enable_if<__VA_ARGS__::value>::type
135141

136142
// Use the nonneg macro when you want to assert that a variable/argument is not negative

lib/pathmatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ PathMatch::PathMatch(std::vector<std::string> patterns, std::string basepath, Sy
3333

3434
bool PathMatch::match(const std::string &path, Filemode mode) const
3535
{
36-
return std::any_of(mPatterns.cbegin(), mPatterns.cend(), [=] (const std::string &pattern) {
36+
return std::any_of(mPatterns.cbegin(), mPatterns.cend(), [&] (const std::string &pattern) {
3737
return match(pattern, path, mBasepath, mode, mSyntax);
3838
});
3939
}

0 commit comments

Comments
 (0)