Fixed #4949 (define symbol used in code => 'Analysis failed' message is written.)

This commit is contained in:
Daniel Marjamäki 2013-08-12 18:12:49 +02:00
parent d6ce072dc9
commit ff71c94f6e
4 changed files with 16 additions and 5 deletions

View File

@ -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();

View File

@ -1642,7 +1642,7 @@ bool Preprocessor::match_cfg_def(std::map<std::string, std::string> 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 "";
}

View File

@ -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

View File

@ -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