codeql-coding-standards
codeql-coding-standards copied to clipboard
`M0-1-9`: Wrong dead code detection on function templates
Affected rules
- M0-1-9
Description
When using template type, some irrelevant M0-1-9 warnings are triggered
Example
template <typename T>
void false_positive() {
T t;
std::cin >> t; // Triggers M0-1-9
}
template <typename T>
void true_negative() {
std::uint32_t u32;
std::cin >> u32;
}
Thanks for the report! This is related to reporting incomplete results in the uninstantiated copy of a template in our model. std::cin >> t is not resolved to a call target in the uninstantiated template copy, so we incorrectly assume it's pure (e.g. no side-effects) and therefore can be removed. We can adjust our concept of pure expression statements to eliminate this case.