github / codeql-coding-standards

This repository contains CodeQL queries and libraries which support various Coding Standards.
MIT License
127 stars 58 forks source link

`A15-4-2`: Only report the first `noexcept` function that throws #159

Closed lcartey closed 9 months ago

lcartey commented 1 year ago

Affected rules

Description

noexcept functions frequently call other noexcept functions. If a noexcept function throws an exception, then we currently report that as a violation in every noexcept function that calls that function. This creates multiple alerts for one issues. We should instead report the original instance and not the others.

Example

void f1() noexcept {
  throw foo(); // report this case
}

void f2() noexcept {
  f1(); // do not report this case
}
lcartey commented 1 year ago
void f3(int i) {
  if (i < 0) {
    throw foo();
  }
}

void f4() noexcept {
  f3(1);
}

void f5() noexcept {
  f4(); // Exclude this call because it's to a noexcept function (i.e. assume noexcept functions can't throw, which is safe because if they do we will report it in that function)
}

Ideal solution: exclude calls to noexcept functions.

Possible solution: exclude only results which directly call noexcept functions that throw (https://github.com/github/codeql-coding-standards/blob/main/cpp/autosar/src/rules/A15-4-2/NoExceptFunctionThrows.ql)