cmake: -Wno-error=something only works by accident
See the code here.
This is the code (slightly shortened):
bool foundNo = false;
bool foundError = false;
unsigned int nameStartPosition = 0;
if (entry.find("no-", nameStartPosition) == 0) {
foundNo = true;
nameStartPosition += 3;
}
if (entry.find("error=", nameStartPosition) == 0) {
foundError = true;
nameStartPosition += 6;
}
name = entry.substr(nameStartPosition);
if (!foundNo && !foundError) {
// -W<name>
this->DiagLevels[name] = std::max(this->DiagLevels[name], DIAG_WARN);
} else if (foundNo && !foundError) {
// -Wno<name>
this->DiagLevels[name] = DIAG_IGNORE;
} else if (!foundNo && foundError) {
// -Werror=<name>
this->DiagLevels[name] = DIAG_ERROR;
} else {
// -Wno-error=<name>
this->DiagLevels[name] = std::min(this->DiagLevels[name], DIAG_WARN);
}
If the first if
matches it will increase nameStartPosition
. The second if
can never become true then, because find(x, nameStartPosition)
can only return values greater nameStartPosition
then.
The coverage shows that the final else
is never executed, but the testcases show that this code somehow has the desired effect. I switched the bogus find()
things to compare()
, which is more efficient as it will stop earlier. Afterwards the testcases break, so there is still something fishy happening afterwards.
Edited by Brad King