Skip to content

Commit ad40586

Browse files
committed
Disable internal checks if NDEBUG is defined (release build)
1 parent 6c02de1 commit ad40586

4 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎lib/checkinternal.cpp‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19+
#ifndef NDEBUG
20+
1921
#include "checkinternal.h"
2022
#include "symboldatabase.h"
2123
#include <string>
2224
#include <set>
2325

2426
using namespace std;
2527

26-
// Register this check class (by creating a static instance of it)
28+
// Register this check class (by creating a static instance of it).
29+
// Disabled in release builds
2730
namespace {
2831
CheckInternal instance;
2932
}
@@ -186,3 +189,5 @@ void CheckInternal::missingPercentCharacterError(const Token* tok, const std::st
186189
"Missing percent end character in Token::" + funcname + "() pattern: \"" + pattern + "\""
187190
);
188191
}
192+
193+
#endif // #ifndef NDEBUG

‎lib/settings.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ std::string Settings::addEnabled(const std::string &str)
8383
id.insert("performance");
8484
id.insert("portability");
8585
id.insert("information");
86-
id.insert("internal");
8786
id.insert("missingInclude");
8887
id.insert("unusedFunction");
88+
#ifndef NDEBUG
89+
id.insert("internal");
90+
#endif
8991

9092
if (str == "all") {
9193
std::set<std::string>::const_iterator it;

‎test/testcmdlineparser.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ class TestCmdlineParser : public TestFixture {
6363
TEST_CASE(enabledPortability);
6464
TEST_CASE(enabledUnusedFunction);
6565
TEST_CASE(enabledMissingInclude);
66+
#ifndef NDEBUG
6667
TEST_CASE(enabledInternal);
68+
#endif
6769
TEST_CASE(errorExitcode);
6870
TEST_CASE(errorExitcodeMissing);
6971
TEST_CASE(errorExitcodeStr);
@@ -445,6 +447,7 @@ class TestCmdlineParser : public TestFixture {
445447
ASSERT(settings.isEnabled("missingInclude"));
446448
}
447449

450+
#ifndef NDEBUG
448451
void enabledInternal() {
449452
REDIRECT;
450453
const char *argv[] = {"cppcheck", "--enable=internal", "file.cpp"};
@@ -453,6 +456,7 @@ class TestCmdlineParser : public TestFixture {
453456
ASSERT(parser.ParseFromArgs(3, argv));
454457
ASSERT(settings.isEnabled("internal"));
455458
}
459+
#endif
456460

457461
void errorExitcode() {
458462
REDIRECT;

‎test/testinternal.cpp‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1717
*/
1818

19-
19+
#ifndef NDEBUG
2020

2121
#include "tokenize.h"
2222
#include "checkinternal.h"
@@ -230,3 +230,5 @@ class TestInternal : public TestFixture {
230230
};
231231

232232
REGISTER_TEST(TestInternal)
233+
234+
#endif // #ifndef NDEBUG

0 commit comments

Comments
 (0)