Fixed #4949 (define symbol used in code => 'Analysis failed' message is written.)
This commit is contained in:
parent
d6ce072dc9
commit
ff71c94f6e
|
@ -224,7 +224,7 @@ unsigned int CppCheck::processFile(const std::string& filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer t("Preprocessor::getcode", _settings._showtime, &S_timerResults);
|
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();
|
t.Stop();
|
||||||
|
|
||||||
const std::string &appendCode = _settings.append();
|
const std::string &appendCode = _settings.append();
|
||||||
|
|
|
@ -1642,7 +1642,7 @@ bool Preprocessor::match_cfg_def(std::map<std::string, std::string> cfg, std::st
|
||||||
return false;
|
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
|
// For the error report
|
||||||
unsigned int lineno = 0;
|
unsigned int lineno = 0;
|
||||||
|
@ -1846,7 +1846,7 @@ std::string Preprocessor::getcode(const std::string &filedata, const std::string
|
||||||
ret << line << "\n";
|
ret << line << "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (validate && !validateCfg(ret.str(), cfg)) {
|
if (!validateCfg(ret.str(), cfg)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,9 +97,8 @@ public:
|
||||||
* @param filedata file data including preprocessing 'if', 'define', etc
|
* @param filedata file data including preprocessing 'if', 'define', etc
|
||||||
* @param cfg configuration to read out
|
* @param cfg configuration to read out
|
||||||
* @param filename name of source file
|
* @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
|
* simplify condition
|
||||||
|
|
|
@ -3858,6 +3858,18 @@ private:
|
||||||
preprocessor.setFile0("test.c");
|
preprocessor.setFile0("test.c");
|
||||||
ASSERT_EQUALS(false, preprocessor.validateCfg("int a=A;", "A"));
|
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());
|
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
|
void if_sizeof() { // #4071
|
||||||
|
|
Loading…
Reference in New Issue