From cf0403434ddc5531a5ed4514e233225aacb34104 Mon Sep 17 00:00:00 2001 From: Robert Reif Date: Wed, 3 Nov 2010 20:33:07 +0100 Subject: [PATCH] Symbol database: Bug fix --- lib/checkclass.cpp | 32 ++++++++++++++++++++++++-------- test/testclass.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2640fb272..0f4dba5f3 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -446,8 +446,20 @@ void CheckClass::createSymbolDatabase() const Token *argStart = 0; // function? - if (tok->previous()->str() == "::" && isFunction(tok, &funcStart, &argStart)) - addFunction(&info, &tok); + if (isFunction(tok, &funcStart, &argStart)) + { + // has body? + if (Token::Match(argStart->link(), ") const| {|:")) + { + // class function + if (tok->previous()->str() == "::") + addFunction(&info, &tok); + + // regular function + else + addNewFunction(&info, &tok); + } + } } } @@ -460,13 +472,17 @@ void CheckClass::createSymbolDatabase() // function? if (isFunction(tok, &funcStart, &argStart)) { - // class function - if (tok->previous()->str() == "::") - addFunction(&info, &tok); + // has body? + if (Token::Match(argStart->link(), ") const| {|:")) + { + // class function + if (tok->previous() && tok->previous()->str() == "::") + addFunction(&info, &tok); - // regular function - else - addNewFunction(&info, &tok); + // regular function + else + addNewFunction(&info, &tok); + } } } } diff --git a/test/testclass.cpp b/test/testclass.cpp index 9109eb5c4..86184b921 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -165,6 +165,7 @@ private: TEST_CASE(symboldatabase1); TEST_CASE(symboldatabase2); TEST_CASE(symboldatabase3); // ticket #2000 + TEST_CASE(symboldatabase4); } // Check the operator Equal @@ -4739,6 +4740,34 @@ private: "};\n"); ASSERT_EQUALS("", errout.str()); } + + void symboldatabase4() + { + checkConst("static void function_declaration_before(void) __attribute__((__used__));\n" + "static void function_declaration_before(void) {}\n" + "static void function_declaration_after(void) {}\n" + "static void function_declaration_after(void) __attribute__((__used__));\n"); + ASSERT_EQUALS("", errout.str()); + + checkConst("main(int argc, char *argv[]) { }\n"); + ASSERT_EQUALS("", errout.str()); + + checkConst("namespace boost {\n" + " std::locale generate_locale()\n" + " {\n" + " return std::locale();\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + + checkConst("namespace X {\n" + " static void function_declaration_before(void) __attribute__((__used__));\n" + " static void function_declaration_before(void) {}\n" + " static void function_declaration_after(void) {}\n" + " static void function_declaration_after(void) __attribute__((__used__));\n" + "}\n"); + ASSERT_EQUALS("", errout.str()); + } }; REGISTER_TEST(TestClass)