diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index 76f6bfd0d..2fcf75ed5 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -224,7 +224,7 @@ unsigned int CppCheck::processFile(const std::string& filename) } Timer t("Preprocessor::getcode", _settings._showtime, &S_timerResults); - const std::string codeWithoutCfg = preprocessor.getcode(filedata, cfg, filename, _settings.isEnabled("information")); + const std::string codeWithoutCfg = preprocessor.getcode(filedata, cfg, filename); t.Stop(); const std::string &appendCode = _settings.append(); diff --git a/lib/preprocessor.cpp b/lib/preprocessor.cpp index 02d9800d6..ad9d87b5c 100644 --- a/lib/preprocessor.cpp +++ b/lib/preprocessor.cpp @@ -1642,7 +1642,7 @@ bool Preprocessor::match_cfg_def(std::map cfg, std::st return false; } -std::string Preprocessor::getcode(const std::string &filedata, const std::string &cfg, const std::string &filename, const bool validate) +std::string Preprocessor::getcode(const std::string &filedata, const std::string &cfg, const std::string &filename) { // For the error report unsigned int lineno = 0; @@ -1846,7 +1846,7 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string ret << line << "\n"; } - if (validate && !validateCfg(ret.str(), cfg)) { + if (!validateCfg(ret.str(), cfg)) { return ""; } diff --git a/lib/preprocessor.h b/lib/preprocessor.h index a15b8cf2f..52eb2e22a 100644 --- a/lib/preprocessor.h +++ b/lib/preprocessor.h @@ -97,9 +97,8 @@ public: * @param filedata file data including preprocessing 'if', 'define', etc * @param cfg configuration to read out * @param filename name of source file - * @param validate true => perform validation that empty configuration macros are not used in the code */ - std::string getcode(const std::string &filedata, const std::string &cfg, const std::string &filename, const bool validate = false); + std::string getcode(const std::string &filedata, const std::string &cfg, const std::string &filename); /** * simplify condition diff --git a/test/testpreprocessor.cpp b/test/testpreprocessor.cpp index 96b95322f..4e1f398ff 100644 --- a/test/testpreprocessor.cpp +++ b/test/testpreprocessor.cpp @@ -3858,6 +3858,18 @@ private: preprocessor.setFile0("test.c"); ASSERT_EQUALS(false, preprocessor.validateCfg("int a=A;", "A")); ASSERT_EQUALS("[test.c:1]: (information) Skipping configuration 'A' since the value of 'A' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.\n", errout.str()); + + // #4949: + // #ifdef A + // a |= A; // <- using macro. must use -D so "A" will get a proper value + errout.str(""); + Settings settings1; + settings = settings1; + ASSERT_EQUALS("", preprocessor.getcode("if (x) a|=A;", "A", "test.c")); + ASSERT_EQUALS("", errout.str()); + settings.addEnabled("information"); + ASSERT_EQUALS("", preprocessor.getcode("if (x) a|=A;", "A", "test.c")); + ASSERT_EQUALS("[test.c:1]: (information) Skipping configuration 'A' since the value of 'A' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.\n", errout.str()); } void if_sizeof() { // #4071