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); 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"