diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 7976e7f0c..9f7173003 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -3482,8 +3482,8 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::mapstr() == "const") { - // just skip "const" + } else if (Token::Match(tok2, "const|extern")) { + // just skip "const", "extern" } else if (!hasstruct && variableId.find(tok2->str()) != variableId.end() && tok2->previous()->str() != "::") { ++typeCount; tok2 = tok2->next(); @@ -3521,6 +3521,8 @@ static bool setVarIdParseDeclaration(const Token **tok, const std::map= 1 && Token::Match(tok2, "( * %name% [") && Token::Match(tok2->linkAt(3), "] ) [;,]")) { bracket = true; + } else if (singleNameCount >= 1 && tok2->previous() && tok2->previous()->isStandardType() && Token::Match(tok2, "( *|&| %name% ) ;")) { + bracket = true; } else if (tok2->str() == "::") { singleNameCount = 0; } else if (tok2->str() != "*" && tok2->str() != "::" && tok2->str() != "...") { diff --git a/test/testincompletestatement.cpp b/test/testincompletestatement.cpp index b4462b2b6..8ddd953ef 100644 --- a/test/testincompletestatement.cpp +++ b/test/testincompletestatement.cpp @@ -614,6 +614,12 @@ private: " return [](int i) { return i > 0; }(s.i);\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + check("extern int (*p);\n" // #10936 + "void f() {\n" + " for (int i = 0; ;) {}\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); } void vardecl() { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index 5209a88f3..19557f7e8 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -96,6 +96,7 @@ private: TEST_CASE(varid62); TEST_CASE(varid63); TEST_CASE(varid64); // #9928 - extern const char (*x[256]) + TEST_CASE(varid65); // #10936 TEST_CASE(varid_for_1); TEST_CASE(varid_for_2); TEST_CASE(varid_cpp_keywords_in_c_code); @@ -1174,6 +1175,29 @@ private: ASSERT_EQUALS(expected, tokenize(code)); } + void varid65() { // #10936 + { + const char code[] = "extern int (*p);"; + const char expected[] = "1: extern int ( * p@1 ) ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + { + const char code[] = "extern int (i);"; + const char expected[] = "1: extern int ( i@1 ) ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + { + const char code[] = "int (*p);"; + const char expected[] = "1: int ( * p@1 ) ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + { + const char code[] = "int (i);"; + const char expected[] = "1: int ( i@1 ) ;\n"; + ASSERT_EQUALS(expected, tokenize(code)); + } + } + void varid_for_1() { const char code[] = "void foo(int a, int b) {\n" " for (int a=1,b=2;;) {}\n"