diff --git a/lib/tokenize.cpp b/lib/tokenize.cpp index 33554dd8ac8..1d5b7436405 100644 --- a/lib/tokenize.cpp +++ b/lib/tokenize.cpp @@ -5083,7 +5083,7 @@ void Tokenizer::setVarIdPass1() if (decl) { if (isC() && Token::Match(prev2->previous(), "&|&&")) syntaxErrorC(prev2, prev2->strAt(-2) + prev2->strAt(-1) + " " + prev2->str()); - variableMap.addVariable(prev2->str(), scopeStack.size() <= 1); + variableMap.addVariable(prev2->str(), scopeStack.size() <= 1 && !functionDeclEndToken); if (Token::simpleMatch(tok->previous(), "for (") && Token::Match(prev2, "%name% [=[({,]")) { for (const Token *tok3 = prev2->next(); tok3 && tok3->str() != ";"; tok3 = tok3->next()) { diff --git a/test/testvarid.cpp b/test/testvarid.cpp index b45074ceea6..a1874d3c5f2 100644 --- a/test/testvarid.cpp +++ b/test/testvarid.cpp @@ -3624,6 +3624,66 @@ class TestVarID : public TestFixture { "8: memset ( :: Z :: b@3 . a , 123 , 5 ) ;\n" "9: }\n"; ASSERT_EQUALS(exp, tokenize(code)); + + const char code2[] = "double d(int);\n" // #15098 + "void g(double d);\n" + "void f() {\n" + " int i = 1;\n" + " double d = 0;\n" + " if (d == ::d(i)) {\n" + " d = ::d(2);\n" + " }\n" + "}\n"; + const char exp2[] = "1: double d ( int ) ;\n" + "2: void g ( double d@1 ) ;\n" + "3: void f ( ) {\n" + "4: int i@2 ; i@2 = 1 ;\n" + "5: double d@3 ; d@3 = 0 ;\n" + "6: if ( d@3 == :: d ( i@2 ) ) {\n" + "7: d@3 = :: d ( 2 ) ;\n" + "8: }\n" + "9: }\n"; + ASSERT_EQUALS(exp2, tokenize(code2)); + + const char code3[] = "double d(int);\n" + "void g(int, double d);\n" + "void f() {\n" + " int i = 1;\n" + " double d = 0;\n" + " if (d == ::d(i)) {\n" + " d = ::d(2);\n" + " }\n" + "}\n"; + const char exp3[] = "1: double d ( int ) ;\n" + "2: void g ( int , double d@1 ) ;\n" + "3: void f ( ) {\n" + "4: int i@2 ; i@2 = 1 ;\n" + "5: double d@3 ; d@3 = 0 ;\n" + "6: if ( d@3 == :: d ( i@2 ) ) {\n" + "7: d@3 = :: d ( 2 ) ;\n" + "8: }\n" + "9: }\n"; + ASSERT_EQUALS(exp3, tokenize(code3)); + + const char code4[] = "double d(int);\n" + "void g(int, double d) { (void)d; }\n" + "void f() {\n" + " int i = 1;\n" + " double d = 0;\n" + " if (d == ::d(i)) {\n" + " d = ::d(2);\n" + " }\n" + "}\n"; + const char exp4[] = "1: double d ( int ) ;\n" + "2: void g ( int , double d@1 ) { ( void ) d@1 ; }\n" + "3: void f ( ) {\n" + "4: int i@2 ; i@2 = 1 ;\n" + "5: double d@3 ; d@3 = 0 ;\n" + "6: if ( d@3 == :: d ( i@2 ) ) {\n" + "7: d@3 = :: d ( 2 ) ;\n" + "8: }\n" + "9: }\n"; + ASSERT_EQUALS(exp4, tokenize(code4)); } void varid_function_pointer_args() {