From 9abe357eb7ddcbdf62116bed3f4af230588d5c31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 6 Aug 2025 13:12:10 +0200 Subject: [PATCH 1/2] add tests --- test/testvarid.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 27efdeed0d1..666751027f3 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -240,6 +240,11 @@ class TestVarID : public TestFixture { TEST_CASE(decltype1); TEST_CASE(decltype2); + TEST_CASE(typeof1); + TEST_CASE(typeof2); + TEST_CASE(typeof3); + TEST_CASE(typeof4); + TEST_CASE(exprid1); TEST_CASE(exprid2); TEST_CASE(exprid3); @@ -4189,6 +4194,30 @@ class TestVarID : public TestFixture { ASSERT_EQUALS(expected, tokenize(code)); } + void typeof1() { + const char code[] = "int x; typeof(x) y;"; + const char expected[] = "1: int x@1 ; typeof ( x@1 ) y@2 ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + + void typeof2() { + const char code[] = "int x; typeof(x) *y;"; + const char expected[] = "1: int x@1 ; typeof ( x@1 ) * y@2 ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + + void typeof3() { + const char code[] = "int x; const typeof(x) *const y;"; + const char expected[] = "1: int x@1 ; const typeof ( x@1 ) * const y@2 ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + + void typeof4() { + const char code[] = "int x; __typeof(x) y;"; + const char expected[] = "1: int x@1 ; __typeof ( x@1 ) y@2 ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + void exprid1() { const std::string actual = tokenizeExpr( "struct A {\n" From 20719811275216a4439c44b1898c19a5c2242cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 6 Aug 2025 13:08:52 +0200 Subject: [PATCH 2/2] fix #13371 --- lib/tokenize.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 5bc04196cff..90bde06cb25 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -4229,7 +4229,7 @@ static bool setVarIdParseDeclaration(Token*& tok, const VariableMap& variableMap } if (tok2->isCpp() && Token::Match(tok2, "namespace|public|private|protected")) return false; - if (tok2->isCpp() && Token::simpleMatch(tok2, "decltype (")) { + if (tok2->isCpp() && Token::Match(tok2, "decltype|typeof|__typeof (")) { typeCount = 1; tok2 = tok2->linkAt(1)->next(); continue; @@ -4782,7 +4782,7 @@ void Tokenizer::setVarIdPass1() variableMap.map(true), mTemplateVarIdUsage); } - if (Token *declTypeTok = Token::findsimplematch(tok, "decltype (", tok2)) { + if (Token *declTypeTok = Token::findmatch(tok, "decltype|typeof|__typeof (", tok2)) { for (Token *declTok = declTypeTok->linkAt(1); declTok != declTypeTok; declTok = declTok->previous()) { if (declTok->isName() && !Token::Match(declTok->previous(), "::|.") && variableMap.hasVariable(declTok->str())) declTok->varId(variableMap.map(false).find(declTok->str())->second);