Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
nbusser-sr opened this issue Oct 18, 2024 · 2 comments
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium Standard-AUTOSAR user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@nbusser-sr
Copy link

nbusser-sr commented Oct 18, 2024

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 nbusser-sr added the false positive/false negative An issue related to observed false positives or false negatives. label Oct 18, 2024
@nbusser-sr nbusser-sr changed the title A5-16-1: Instanciating string is considered as sub-expression A5-16-1: Constructing string is considered as sub-expression Oct 18, 2024
@nbusser-sr nbusser-sr changed the title A5-16-1: Constructing string is considered as sub-expression A5-16-1: Constructing std::string is considered as sub-expression in ternary operation Oct 18, 2024
@nbusser-sr
Copy link
Author

nbusser-sr commented Oct 18, 2024

Possibly a duplicate of my own old ticket #612 😮‍💨
Sorry for the inconvenience

@lcartey lcartey added the user-report Issue reported by an end user of CodeQL Coding Standards label Oct 18, 2024
@lcartey lcartey moved this from Reported to Done in Coding Standards Public Development Board Oct 18, 2024
@lcartey
Copy link
Collaborator

lcartey commented Oct 18, 2024

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

@lcartey lcartey added Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address Impact-Medium labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Medium Standard-AUTOSAR user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

No branches or pull requests

3 participants