From dca03c3ce2ba61acd974da55dc581b33d70b5948 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Fri, 23 Dec 2011 23:31:48 +0200 Subject: [PATCH] Remove unnecessary includes Also add a unit test related to #3427 Also improve the description text in checkclass and remove unused variable. --- cli/cppcheckexecutor.cpp | 1 - cli/threadexecutor.cpp | 2 +- lib/checkautovariables.cpp | 3 +-- lib/checkautovariables.h | 1 - lib/checkboost.cpp | 2 -- lib/checkbufferoverrun.cpp | 7 +------ lib/checkclass.cpp | 1 - lib/checkclass.h | 8 ++++---- lib/checkmemoryleak.cpp | 1 + lib/checkmemoryleak.h | 3 +-- lib/checkobsoletefunctions.h | 2 +- lib/cppcheck.h | 1 - lib/errorlogger.h | 1 - lib/mathlib.cpp | 1 - lib/preprocessor.cpp | 1 - lib/suppressions.cpp | 1 - lib/symboldatabase.cpp | 2 -- test/testclass.cpp | 4 ++-- test/testcppcheck.cpp | 3 +-- test/teststl.cpp | 8 ++++++++ test/testthreadexecutor.cpp | 3 +-- test/testtoken.cpp | 1 - test/testutils.h | 4 +++- 23 files changed, 25 insertions(+), 36 deletions(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index 0676a71c3..1112455f9 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -21,7 +21,6 @@ #include "threadexecutor.h" #include "preprocessor.h" #include "errorlogger.h" -#include #include #include // EXIT_SUCCESS and EXIT_FAILURE #include diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 25b80e655..6896184d2 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -19,9 +19,9 @@ #include "cppcheckexecutor.h" #include "threadexecutor.h" #include "cppcheck.h" -#include #include #ifdef THREADING_MODEL_FORK +#include #include #include #include diff --git a/lib/checkautovariables.cpp b/lib/checkautovariables.cpp index 4b17a5fc5..e0f83e94c 100644 --- a/lib/checkautovariables.cpp +++ b/lib/checkautovariables.cpp @@ -23,8 +23,7 @@ #include "checkautovariables.h" #include "symboldatabase.h" -#include -#include +#include #include //--------------------------------------------------------------------------- diff --git a/lib/checkautovariables.h b/lib/checkautovariables.h index 8a81b1a90..d15b63a95 100644 --- a/lib/checkautovariables.h +++ b/lib/checkautovariables.h @@ -24,7 +24,6 @@ #include "check.h" #include "token.h" -#include /// @addtogroup Checks /// @{ diff --git a/lib/checkboost.cpp b/lib/checkboost.cpp index 6007f33a7..f45cba087 100644 --- a/lib/checkboost.cpp +++ b/lib/checkboost.cpp @@ -17,8 +17,6 @@ */ #include "checkboost.h" -#include "symboldatabase.h" -#include // Register this check class (by creating a static instance of it) namespace { diff --git a/lib/checkbufferoverrun.cpp b/lib/checkbufferoverrun.cpp index d92ed4654..40dfcee5c 100644 --- a/lib/checkbufferoverrun.cpp +++ b/lib/checkbufferoverrun.cpp @@ -30,12 +30,8 @@ #include #include #include -#include -#include -#include - #include // <- assert -#include // <- strtoul +#include //--------------------------------------------------------------------------- @@ -2160,7 +2156,6 @@ void CheckBufferOverrun::arrayIndexThenCheck() return; for (const Token *tok = _tokenizer->tokens(); tok; tok = tok->next()) { if (Token::Match(tok, "%var% [ %var% ]")) { - const std::string arrayName(tok->str()); const std::string indexName(tok->strAt(2)); // skip array index.. diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 8bc2c01c5..9f3d4ce6c 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -24,7 +24,6 @@ #include "errorlogger.h" #include "symboldatabase.h" -#include #include #include diff --git a/lib/checkclass.h b/lib/checkclass.h index 8b8b107ef..10238e877 100644 --- a/lib/checkclass.h +++ b/lib/checkclass.h @@ -22,10 +22,10 @@ //--------------------------------------------------------------------------- #include "check.h" -#include "settings.h" -#include "symboldatabase.h" class Token; +class Scope; +class Function; /// @addtogroup Checks /// @{ @@ -147,8 +147,8 @@ private: return "Check the code for each class.\n" "* Missing constructors\n" "* Are all variables initialized by the constructors?\n" - "* [[CheckMemset|Warn if memset, memcpy etc are used on a class]]\n" - //"* If it's a base class, check that the destructor is virtual\n" + "* Warn if memset, memcpy etc are used on a class\n" + "* If it's a base class, check that the destructor is virtual\n" "* Are there unused private functions\n" "* 'operator=' should return reference to self\n" "* 'operator=' should check for assignment to self\n" diff --git a/lib/checkmemoryleak.cpp b/lib/checkmemoryleak.cpp index c2a56936e..80ffe78af 100644 --- a/lib/checkmemoryleak.cpp +++ b/lib/checkmemoryleak.cpp @@ -18,6 +18,7 @@ #include "checkmemoryleak.h" +#include "symboldatabase.h" #include "mathlib.h" #include "tokenize.h" diff --git a/lib/checkmemoryleak.h b/lib/checkmemoryleak.h index ea5ed937f..93b4a0f7d 100644 --- a/lib/checkmemoryleak.h +++ b/lib/checkmemoryleak.h @@ -35,13 +35,12 @@ */ #include "check.h" -#include "symboldatabase.h" #include #include -#include class Token; +class Scope; /// @addtogroup Core /// @{ diff --git a/lib/checkobsoletefunctions.h b/lib/checkobsoletefunctions.h index 24d19961d..bf7adfb43 100644 --- a/lib/checkobsoletefunctions.h +++ b/lib/checkobsoletefunctions.h @@ -24,7 +24,7 @@ #include "check.h" #include -#include +#include /// @addtogroup Checks diff --git a/lib/cppcheck.h b/lib/cppcheck.h index d9a1b7a0f..b570a8f85 100644 --- a/lib/cppcheck.h +++ b/lib/cppcheck.h @@ -26,7 +26,6 @@ #include #include #include -#include /// @addtogroup Core /// @{ diff --git a/lib/errorlogger.h b/lib/errorlogger.h index bbc826599..8bf645d5c 100644 --- a/lib/errorlogger.h +++ b/lib/errorlogger.h @@ -23,7 +23,6 @@ #include #include -#include "settings.h" #include "suppressions.h" class Token; diff --git a/lib/mathlib.cpp b/lib/mathlib.cpp index 305cf0b7b..367f1dd64 100644 --- a/lib/mathlib.cpp +++ b/lib/mathlib.cpp @@ -22,7 +22,6 @@ #include "tokenize.h" #include -#include #include #include #include diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 4daa58dbf..4c2e6c9c6 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include diff --git a/lib/suppressions.cpp b/lib/suppressions.cpp index 137bb0ff8..1527ca999 100644 --- a/lib/suppressions.cpp +++ b/lib/suppressions.cpp @@ -21,7 +21,6 @@ #include "path.h" #include -#include #include #include // std::isdigit, std::isalnum, etc diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index 411a7375f..a6fdeda60 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -25,10 +25,8 @@ #include "errorlogger.h" #include "check.h" -#include #include #include -#include #include // Define ULLONG_MAX and LLONG_MAX for Borland diff --git a/test/testclass.cpp b/test/testclass.cpp index 47d0bb078..0f6c5e565 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -1606,7 +1606,7 @@ private: checkVirtualDestructor("class Base\n" "{\n" "public:\n" - "~Base() {}\n" + " ~Base() {}\n" "};\n" "class A : private Base\n" "{\n" @@ -1619,7 +1619,7 @@ private: "public:\n" " ~B() { int a; }\n" "};\n"); - TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class A which is inherited by class B does not have a virtual destructor\n", + TODO_ASSERT_EQUALS("[test.cpp:7]: (error) Class Base which is inherited by class B does not have a virtual destructor\n", "", errout.str()); } diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 1e3c63247..4c4a9830f 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -27,9 +27,8 @@ #include "path.h" #include -#include +#include #include -#include // use tinyxml with STL #include diff --git a/test/teststl.cpp b/test/teststl.cpp index cad2a52d9..c5d552a4d 100644 --- a/test/teststl.cpp +++ b/test/teststl.cpp @@ -1394,6 +1394,14 @@ private: " const char *c = f().c_str();\n" "}"); ASSERT_EQUALS("[test.cpp:4]: (error) Dangerous usage of c_str(). The returned value by c_str() is invalid after this call.\n", errout.str()); + + + check("const char* foo() {\n" + " static std::string text;\n" + " text = \"hello world\n\";\n" + " return text.c_str();\n" + "}"); + ASSERT_EQUALS("", errout.str()); // #3427 } void autoPointer() { diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index b5f838973..e0bfc9d10 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -26,10 +26,9 @@ #include "threadexecutor.h" #include "cppcheckexecutor.h" -#include #include #include -#include +#include extern std::ostringstream errout; extern std::ostringstream output; diff --git a/test/testtoken.cpp b/test/testtoken.cpp index 6ef0b1938..e39aee1a4 100644 --- a/test/testtoken.cpp +++ b/test/testtoken.cpp @@ -21,7 +21,6 @@ #include "token.h" #include "settings.h" -#include #include #include diff --git a/test/testutils.h b/test/testutils.h index 2a683029d..654c57479 100644 --- a/test/testutils.h +++ b/test/testutils.h @@ -18,9 +18,11 @@ #ifndef TestUtilsH #define TestUtilsH + #include "settings.h" #include "tokenize.h" -#include "token.h" + +class Token; class givenACodeSampleToTokenize { private: