Skip to content

Commit

Permalink
Set varid
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Oct 4, 2023
1 parent 9fcdaab commit cc4899c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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")
;
Expand Down
11 changes: 11 additions & 0 deletions test/testvarid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit cc4899c

Please sign in to comment.