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

`A5-16-1`: Constructing `std::string` is considered as sub-expression in ternary operation

Open nbusser-sr opened this issue 1 year ago • 2 comments

Affected rules

  • A5-16-1: cpp/autosar/ternary-conditional-operator-used-as-sub-expression

Rule A5-16-1 (required, implementation, automated) The ternary conditional operator shall not be used as a sub-expression.

Description

When initializing a string inside a ternary expression, A5-16-1 error is triggered.
I tried with std::uint32_t and with a class, and the error was not triggered.

Example

std::string const str{cond ? "str1" : "str2"}; // Triggers A5-16-1

Test const test{cond ? Test() : Test()}; // Ok
std::uint32_t const nb{cond ? 0 : 1}; // Ok

nbusser-sr avatar Oct 18 '24 02:10 nbusser-sr

Possibly a duplicate of my own old ticket https://github.com/github/codeql-coding-standards/issues/612 :face_exhaling:
Sorry for the inconvenience

nbusser-sr avatar Oct 18 '24 02:10 nbusser-sr

Thanks @nbusser-sr! I don't think this is a duplicate, although we will likely fix this at the same time.

lcartey avatar Oct 18 '24 08:10 lcartey