codeql-coding-standards icon indicating copy to clipboard operation
codeql-coding-standards copied to clipboard

`M0-1-9`: Wrong dead code detection on function templates

Open nbusser opened this issue 1 year ago • 1 comments

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;
}

nbusser avatar Jun 01 '24 17:06 nbusser

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.

lcartey avatar Jun 07 '24 08:06 lcartey