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

`A15-4-2`: Ignore elided calls when calculating the exception graph

Open lcartey opened this issue 2 years ago • 2 comments

Affected rules

  • A15-4-2

Description

Copy elision allows the compiler to omit copy and move construction in certain circumstances. Some of these circumstances are considered "mandatory" - i.e. the compiler must omit the explicit construction - and in those circumstances copy and move constructors may never be called.

If you have move/copy constructors which are never expected to be called because they are always elided, you may decide to throw an exception from the copy/move constructor to enforce that it is only used in circumstances where the elision occurs. As our call graph does not currently reflect the mandatory elision of functions, this can cause false positives.

Example

// `foo` is only used in circumstances where it is elided, so this exception is never thrown in practice
constexpr foo(const foo&) : dummy() {
  throw some_bad_exception();
};

lcartey avatar Jan 06 '23 13:01 lcartey

See also: https://github.com/github/codeql-coding-standards/issues/20 As it appears we do sometimes elide the copy/move constructors.

lcartey avatar Jan 06 '23 13:01 lcartey

Modify https://github.com/github/codeql-coding-standards/blob/main/cpp/common/src/codingstandards/cpp/exceptions/ExceptionFlow.qll#LL315C49-L315C97 to exclude calls to copy or move constructors we think are elided.

lcartey avatar Mar 17 '23 16:03 lcartey