github / codeql-coding-standards

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

`A15-1-3`: Detection of duplicated exceptions on function templates #603

Open nbusser opened 5 months ago

nbusser commented 5 months ago

Affected rules

Description

When defining a function template which throws an exception, A15-1-3 warning is triggered, meaning that the exception is not unique.

Example

template <typename T>
void false_positive() {
  throw std::runtime_error{"message"}; // Triggers A15-1-3 warning
}
lcartey commented 5 months ago

Thanks for reporting!

This occurs because we have a separate representation for each template instantiation in our database representation of the program, so we consider the exception to be "duplicated" in each instantiation. The AUTOSAR rule does not clarify the expected behaviour in this case, but I believe it would be reasonable to not report this case.