Skip to content

Commit 7a33ca6

Browse files
committed
fix
1 parent c10a3ee commit 7a33ca6

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎lib/tokenize.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4783,7 +4783,7 @@ void Tokenizer::setVarId()
47834783
#define NOTSTART_C "NOT", "case", "default", "goto", "not", "return", "sizeof", "typedef"
47844784
static const std::unordered_set<std::string> notstart_c = { NOTSTART_C };
47854785
static const std::unordered_set<std::string> notstart_cpp = { NOTSTART_C,
4786-
"delete", "friend", "new", "throw", "using", "virtual", "explicit", "const_cast", "dynamic_cast", "reinterpret_cast", "static_cast", "template"
4786+
"delete", "friend", "new", "throw", "using", "virtual", "explicit", "const_cast", "dynamic_cast", "reinterpret_cast", "static_cast", "template", "requires"
47874787
};
47884788

47894789
// Returns the end of the lambda that starts at tok in a constructor initializer list, or nullptr
@@ -4988,8 +4988,8 @@ void Tokenizer::setVarIdPass1()
49884988
(tok->isName() && endsWith(tok->str(), ':')))) ||
49894989
(tok->str() == "(" && TokenList::isFunctionHead(tok, "{"))) {
49904990

4991-
// No variable declarations in sizeof
4992-
if (Token::simpleMatch(tok->previous(), "sizeof (")) {
4991+
// No variable declarations in sizeof and static_assert
4992+
if (Token::Match(tok->previous(), "sizeof|static_assert|_Static_assert (")) {
49934993
continue;
49944994
}
49954995

@@ -5126,7 +5126,7 @@ void Tokenizer::setVarIdPass1()
51265126

51275127
if (Token::simpleMatch(tok->previous(), "for (") && Token::Match(prev2, "%name% [=[({,]")) {
51285128
for (const Token *tok3 = prev2->next(); tok3 && tok3->str() != ";"; tok3 = tok3->next()) {
5129-
if (Token::Match(tok3, "[([]"))
5129+
if (Token::Match(tok3, "[([{]"))
51305130
tok3 = tok3->link();
51315131
if (Token::Match(tok3, ", %name% [=[({,;]"))
51325132
variableMap.addVariable(tok3->strAt(1), false);

‎test/testvarid.cpp‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ class TestVarID : public TestFixture {
106106
TEST_CASE(varid_for_1);
107107
TEST_CASE(varid_for_2);
108108
TEST_CASE(varid_for_3);
109+
TEST_CASE(varid_for_4);
110+
TEST_CASE(varid_static_assert);
111+
TEST_CASE(varid_requires);
109112
TEST_CASE(varid_cpp_keywords_in_c_code);
110113
TEST_CASE(varid_cpp_keywords_in_c_code2); // #5373: varid=0 for argument called "delete"
111114
TEST_CASE(varid_cpp_keywords_in_c_code3);
@@ -1461,6 +1464,32 @@ class TestVarID : public TestFixture {
14611464
ASSERT_EQUALS(expected2, tokenize(code2));
14621465
}
14631466

1467+
void varid_for_4() {
1468+
const char code[] = "void f(int x) {\n"
1469+
" for (V v{ 1, x, true }; ;) { x = 1; }\n"
1470+
"}\n";
1471+
const char expected[] = "1: void f ( int x@1 ) {\n"
1472+
"2: for ( V v@2 { 1 , x@1 , true } ; ; ) { x@1 = 1 ; }\n"
1473+
"3: }\n";
1474+
ASSERT_EQUALS(expected, tokenize(code));
1475+
}
1476+
1477+
void varid_static_assert() {
1478+
const char code[] = "struct S { static const bool v = false; };\n"
1479+
"static_assert(S::v && true, \"\");\n";
1480+
const char expected[] = "1: struct S { static const bool v@1 = false ; } ;\n"
1481+
"2: static_assert ( S :: v@1 && true , \"\" ) ;\n";
1482+
ASSERT_EQUALS(expected, tokenize(code));
1483+
}
1484+
1485+
void varid_requires() {
1486+
const char code[] = "template<class T>\n"
1487+
"concept C = requires (T x) { requires true; };\n";
1488+
const char expected[] = "1: template < class T >\n"
1489+
"2: concept C = requires ( T x@1 ) { requires true ; } ;\n";
1490+
ASSERT_EQUALS(expected, tokenize(code));
1491+
}
1492+
14641493
void varid_cpp_keywords_in_c_code() {
14651494
const char code[] = "void f() {\n"
14661495
" delete d;\n"

0 commit comments

Comments
 (0)