Preprocessor::getConfigs: Handle #error in '#if !A' better
This commit is contained in:
parent
87bc667289
commit
7eb95aac2a
|
@ -375,6 +375,14 @@ static void getConfigs(const simplecpp::TokenList &tokens, std::set<std::string>
|
|||
configs.push_back(configs_ifndef.back());
|
||||
ret.insert(cfg(configs, userDefines));
|
||||
}
|
||||
if (!configs_if.empty() && !configs_if.back().empty()) {
|
||||
const std::string &last = configs_if.back();
|
||||
if (last.size() > 2U && last.compare(last.size()-2U,2,"=0") == 0) {
|
||||
std::vector<std::string> configs(configs_if);
|
||||
configs[configs.size() - 1U] = last.substr(0,last.size()-2U);
|
||||
ret.insert(cfg(configs, userDefines));
|
||||
}
|
||||
}
|
||||
} else if (cmdtok->str == "define" && sameline(tok, cmdtok->next) && cmdtok->next->name) {
|
||||
defined.insert(cmdtok->next->str);
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ private:
|
|||
TEST_CASE(Bug2190219);
|
||||
|
||||
TEST_CASE(error1); // #error => don't extract any code
|
||||
TEST_CASE(error2); // #error if symbol is not defined
|
||||
TEST_CASE(error3);
|
||||
TEST_CASE(error4); // #2919 - wrong filename is reported
|
||||
TEST_CASE(error5);
|
||||
|
@ -319,6 +320,18 @@ private:
|
|||
ASSERT_EQUALS("\nA\n", getConfigsStr(filedata));
|
||||
}
|
||||
|
||||
void error2() {
|
||||
const char filedata1[] = "#ifndef A\n"
|
||||
"#error\n"
|
||||
"#endif\n";
|
||||
TODO_ASSERT_EQUALS("A\n", "\nA\n", getConfigsStr(filedata1));
|
||||
|
||||
const char filedata2[] = "#if !A\n"
|
||||
"#error\n"
|
||||
"#endif\n";
|
||||
TODO_ASSERT_EQUALS("A\n", "\nA\nA=0\n", getConfigsStr(filedata2));
|
||||
}
|
||||
|
||||
void error3() {
|
||||
errout.str("");
|
||||
Settings settings;
|
||||
|
|
Loading…
Reference in New Issue