Skip to content

Commit 72197bb

Browse files
Fix #13338 FN passedByValueCallback with braced initializer (danmar#7558)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent dc0f5a1 commit 72197bb

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/symboldatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ void SymbolDatabase::createSymbolDatabaseSetFunctionPointers(bool firstPass)
11561156
inTemplateArg = tok->link();
11571157
if (inTemplateArg == tok)
11581158
inTemplateArg = nullptr;
1159-
if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{(,)>;:]]")) && !isReservedName(tok)) {
1159+
if (tok->isName() && !tok->function() && tok->varId() == 0 && ((tok->astParent() && tok->astParent()->isComparisonOp()) || Token::Match(tok, "%name% [{}(,)>;:]]")) && !isReservedName(tok)) {
11601160
if (tok->strAt(1) == ">" && !tok->linkAt(1))
11611161
continue;
11621162

test/testother.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3935,6 +3935,15 @@ class TestOther : public TestFixture {
39353935
ASSERT_EQUALS("[test.cpp:3:8] -> [test.cpp:1:13]: (style) Parameter 'p' can be declared as pointer to const. "
39363936
"However it seems that 'f' is a callback function, if 'p' is declared with const you might also need to cast function pointer(s). [constParameterCallback]\n",
39373937
errout_str());
3938+
3939+
check("struct S { explicit S(std::function<void(std::string)>); };\n" // #13338
3940+
"void cb(std::string s) {\n"
3941+
" (void)s.empty();\n"
3942+
"}\n"
3943+
"void f() {\n"
3944+
" S s2{ cb };\n"
3945+
"}\n");
3946+
ASSERT_EQUALS("[test.cpp:6:11] -> [test.cpp:2:21]: (performance) Function parameter 's' should be passed by const reference. However it seems that 'cb' is a callback function. [passedByValueCallback]\n", errout_str());
39383947
}
39393948

39403949
void constPointer() {

0 commit comments

Comments
 (0)