From ad40586e9604b1faf4df84d6526348be1d3e9236 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Sat, 29 Oct 2011 12:47:12 +0200 Subject: [PATCH] Disable internal checks if NDEBUG is defined (release build) --- lib/checkinternal.cpp | 7 ++++++- lib/settings.cpp | 4 +++- test/testcmdlineparser.cpp | 4 ++++ test/testinternal.cpp | 4 +++- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/checkinternal.cpp b/lib/checkinternal.cpp index 9112d01ce..c392635bc 100644 --- a/lib/checkinternal.cpp +++ b/lib/checkinternal.cpp @@ -16,6 +16,8 @@ * along with this program. If not, see . */ +#ifndef NDEBUG + #include "checkinternal.h" #include "symboldatabase.h" #include @@ -23,7 +25,8 @@ using namespace std; -// Register this check class (by creating a static instance of it) +// Register this check class (by creating a static instance of it). +// Disabled in release builds namespace { CheckInternal instance; } @@ -186,3 +189,5 @@ void CheckInternal::missingPercentCharacterError(const Token* tok, const std::st "Missing percent end character in Token::" + funcname + "() pattern: \"" + pattern + "\"" ); } + +#endif // #ifndef NDEBUG diff --git a/lib/settings.cpp b/lib/settings.cpp index 57175c2bc..559e07bb7 100644 --- a/lib/settings.cpp +++ b/lib/settings.cpp @@ -83,9 +83,11 @@ std::string Settings::addEnabled(const std::string &str) id.insert("performance"); id.insert("portability"); id.insert("information"); - id.insert("internal"); id.insert("missingInclude"); id.insert("unusedFunction"); +#ifndef NDEBUG + id.insert("internal"); +#endif if (str == "all") { std::set::const_iterator it; diff --git a/test/testcmdlineparser.cpp b/test/testcmdlineparser.cpp index db316463e..55399d883 100644 --- a/test/testcmdlineparser.cpp +++ b/test/testcmdlineparser.cpp @@ -63,7 +63,9 @@ private: TEST_CASE(enabledPortability); TEST_CASE(enabledUnusedFunction); TEST_CASE(enabledMissingInclude); +#ifndef NDEBUG TEST_CASE(enabledInternal); +#endif TEST_CASE(errorExitcode); TEST_CASE(errorExitcodeMissing); TEST_CASE(errorExitcodeStr); @@ -445,6 +447,7 @@ private: ASSERT(settings.isEnabled("missingInclude")); } +#ifndef NDEBUG void enabledInternal() { REDIRECT; const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"}; @@ -453,6 +456,7 @@ private: ASSERT(parser.ParseFromArgs(3, argv)); ASSERT(settings.isEnabled("internal")); } +#endif void errorExitcode() { REDIRECT; diff --git a/test/testinternal.cpp b/test/testinternal.cpp index 67dba8332..b84bb5aa7 100644 --- a/test/testinternal.cpp +++ b/test/testinternal.cpp @@ -16,7 +16,7 @@ * along with this program. If not, see . */ - +#ifndef NDEBUG #include "tokenize.h" #include "checkinternal.h" @@ -230,3 +230,5 @@ private: }; REGISTER_TEST(TestInternal) + +#endif // #ifndef NDEBUG