diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index af2323484ca..b73ea16bfc9 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4613,6 +4613,10 @@ void Tokenizer::setVarIdPass1() } catch (const Token * errTok) { syntaxError(errTok); } + + if (tok->str() == "(" && isFunctionHead(tok, "{") && scopeStack.top().isExecutable) + inlineFunction = true; + if (decl) { if (isCPP()) { if (Token *declTypeTok = Token::findsimplematch(tok, "decltype (", tok2)) { @@ -4623,9 +4627,6 @@ void Tokenizer::setVarIdPass1() } } - if (tok->str() == "(" && isFunctionHead(tok,"{") && scopeStack.top().isExecutable) - inlineFunction = true; - const Token* prev2 = tok2->previous(); if (Token::Match(prev2, "%type% [;[=,)]") && tok2->previous()->str() != "const") ; diff --git a/test/testvarid.cpp b/test/testvarid.cpp index c3d2fcd76bf..a4d709b69f8 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -100,6 +100,7 @@ class TestVarID : public TestFixture { TEST_CASE(varid66); TEST_CASE(varid67); // #11711 - NOT function pointer TEST_CASE(varid68); // #11740 - switch (str_chars(&strOut)[0]) + TEST_CASE(varid69); TEST_CASE(varid_for_1); TEST_CASE(varid_for_2); TEST_CASE(varid_cpp_keywords_in_c_code); @@ -1241,6 +1242,16 @@ class TestVarID : public TestFixture { ASSERT_EQUALS(expected1, tokenize(code1, "test.cpp")); } + void varid69() { + const char code1[] = "void f() {\n" + " auto g = [](int&, int& r, int i) {};\n" + "}"; + const char expected1[] = "1: void f ( ) {\n" + "2: auto g@1 ; g@1 = [ ] ( int & , int & r@2 , int i@3 ) { } ;\n" + "3: }\n"; + ASSERT_EQUALS(expected1, tokenize(code1, "test.cpp")); + } + void varid_for_1() { const char code[] = "void foo(int a, int b) {\n" " for (int a=1,b=2;;) {}\n"