Preprocessor: removed unreachable `ConfigurationNotChecked` finding (#4790)
This commit is contained in:
parent
bd1ae69b00
commit
381361629e
|
@ -725,10 +725,6 @@ simplecpp::TokenList Preprocessor::preprocess(const simplecpp::TokenList &tokens
|
|||
|
||||
tokens2.removeComments();
|
||||
|
||||
// ensure that guessed define macros without value are not used in the code
|
||||
if (!validateCfg(cfg, macroUsage))
|
||||
return simplecpp::TokenList(files);
|
||||
|
||||
return tokens2;
|
||||
}
|
||||
|
||||
|
@ -878,44 +874,6 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
|
|||
}
|
||||
}
|
||||
|
||||
bool Preprocessor::validateCfg(const std::string &cfg, const std::list<simplecpp::MacroUsage> ¯oUsageList)
|
||||
{
|
||||
bool ret = true;
|
||||
std::list<std::string> defines;
|
||||
splitcfg(cfg, defines, emptyString);
|
||||
for (const std::string &define : defines) {
|
||||
if (define.find('=') != std::string::npos)
|
||||
continue;
|
||||
const std::string macroName(define.substr(0, define.find('(')));
|
||||
for (const simplecpp::MacroUsage &mu : macroUsageList) {
|
||||
if (mu.macroValueKnown)
|
||||
continue;
|
||||
if (mu.macroName != macroName)
|
||||
continue;
|
||||
const bool directiveLocation = std::any_of(mDirectives.cbegin(), mDirectives.cend(),
|
||||
[=](const Directive &dir) {
|
||||
return mu.useLocation.file() == dir.file && mu.useLocation.line == dir.linenr;
|
||||
});
|
||||
|
||||
if (!directiveLocation) {
|
||||
if (mSettings.severity.isEnabled(Severity::information))
|
||||
validateCfgError(mu.useLocation.file(), mu.useLocation.line, cfg, macroName);
|
||||
ret = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Preprocessor::validateCfgError(const std::string &file, const unsigned int line, const std::string &cfg, const std::string ¯o)
|
||||
{
|
||||
const std::string id = "ConfigurationNotChecked";
|
||||
ErrorMessage::FileLocation loc(file, line, 0);
|
||||
const ErrorMessage errmsg({std::move(loc)}, mFile0, Severity::information, "Skipping configuration '" + cfg + "' since the value of '" + macro + "' is unknown. Use -D if you want to check it. You can use -U to skip it explicitly.", id, Certainty::normal);
|
||||
mErrorLogger->reportInfo(errmsg);
|
||||
}
|
||||
|
||||
void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *settings)
|
||||
{
|
||||
Settings settings2(*settings);
|
||||
|
@ -923,7 +881,6 @@ void Preprocessor::getErrorMessages(ErrorLogger *errorLogger, const Settings *se
|
|||
settings2.checkConfiguration = true;
|
||||
preprocessor.missingInclude(emptyString, 1, emptyString, UserHeader);
|
||||
preprocessor.missingInclude(emptyString, 1, emptyString, SystemHeader);
|
||||
preprocessor.validateCfgError(emptyString, 1, "X", "X");
|
||||
preprocessor.error(emptyString, 1, "#error message"); // #error ..
|
||||
}
|
||||
|
||||
|
|
|
@ -156,15 +156,6 @@ public:
|
|||
*/
|
||||
std::string getcode(const std::string &filedata, const std::string &cfg, const std::string &filename);
|
||||
|
||||
/**
|
||||
* make sure empty configuration macros are not used in code. the given code must be a single configuration
|
||||
* @param cfg configuration
|
||||
* @param macroUsageList macro usage list
|
||||
* @return true => configuration is valid
|
||||
*/
|
||||
bool validateCfg(const std::string &cfg, const std::list<simplecpp::MacroUsage> ¯oUsageList);
|
||||
void validateCfgError(const std::string &file, const unsigned int line, const std::string &cfg, const std::string ¯o);
|
||||
|
||||
/**
|
||||
* Calculate HASH. Using toolinfo, tokens1, filedata.
|
||||
*
|
||||
|
|
|
@ -244,9 +244,6 @@ private:
|
|||
TEST_CASE(getConfigsU6);
|
||||
TEST_CASE(getConfigsU7);
|
||||
|
||||
TEST_CASE(validateCfg1);
|
||||
TEST_CASE(validateCfg2);
|
||||
|
||||
TEST_CASE(if_sizeof);
|
||||
|
||||
TEST_CASE(invalid_ifs); // #5909
|
||||
|
@ -274,6 +271,7 @@ private:
|
|||
TEST_CASE(testMissingIncludeCheckConfig);
|
||||
}
|
||||
|
||||
// TODO: we should be calling the actual Preprocessor::preprocess() implementation
|
||||
void preprocess(const char* code, std::map<std::string, std::string>& actual, const char filename[] = "file.c") {
|
||||
errout.str("");
|
||||
std::istringstream istr(code);
|
||||
|
@ -2281,37 +2279,6 @@ private:
|
|||
ASSERT_EQUALS("\nY\n", getConfigsStr(code, "-DX"));
|
||||
}
|
||||
|
||||
|
||||
void validateCfg1() {
|
||||
Preprocessor preprocessor(settings0, this);
|
||||
|
||||
std::vector<std::string> files(1, "test.c");
|
||||
simplecpp::MacroUsage macroUsage(files, false);
|
||||
macroUsage.useLocation.fileIndex = 0;
|
||||
macroUsage.useLocation.line = 1;
|
||||
macroUsage.macroName = "X";
|
||||
std::list<simplecpp::MacroUsage> macroUsageList(1, macroUsage);
|
||||
|
||||
ASSERT_EQUALS(true, preprocessor.validateCfg("", macroUsageList));
|
||||
ASSERT_EQUALS(false, preprocessor.validateCfg("X",macroUsageList));
|
||||
ASSERT_EQUALS(false, preprocessor.validateCfg("A=42;X", macroUsageList));
|
||||
ASSERT_EQUALS(true, preprocessor.validateCfg("X=1", macroUsageList));
|
||||
ASSERT_EQUALS(true, preprocessor.validateCfg("Y", macroUsageList));
|
||||
|
||||
macroUsageList.front().macroValueKnown = true; // #8404
|
||||
ASSERT_EQUALS(true, preprocessor.validateCfg("X", macroUsageList));
|
||||
}
|
||||
|
||||
void validateCfg2() {
|
||||
const char filedata[] = "#ifdef ABC\n"
|
||||
"#endif\n"
|
||||
"int i = ABC;";
|
||||
|
||||
std::map<std::string, std::string> actual;
|
||||
preprocess(filedata, actual, "file.cpp");
|
||||
ASSERT_EQUALS("[file.cpp:3]: (information) Skipping configuration 'ABC' since the value of 'ABC' 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
|
||||
static const char* code = "#if sizeof(unsigned short) == 2\n"
|
||||
"Fred & Wilma\n"
|
||||
|
|
Loading…
Reference in New Issue