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

DCL53-CPP: Reports non syntactically ambiguous object declarations #812

Open
lcartey opened this issue Dec 6, 2024 · 0 comments
Open

DCL53-CPP: Reports non syntactically ambiguous object declarations #812

lcartey opened this issue Dec 6, 2024 · 0 comments
Labels
Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low

Comments

@lcartey
Copy link
Collaborator

lcartey commented Dec 6, 2024

Affected rules

  • DCL53-CPP

Description

LocalConstructorInitializedObjectHidesIdentifier.ql currently identifies variable declarations that call a constructor and hide an outer scope variable. However, this does not fully capture the cases covered by this vexing parsing situation, which is looking for S1(g1).

The following additions to the query could help address this problem:

  v.getInitializer().getExpr().(ConstructorCall).getNumberOfArguments() = 0 and
  not v.getInitializer().isBraced()

However this would still flag S1 g3; below - as we don't currently have a record of where the brackets were during parsing.

Example

This modification of the test case highlights the problems:

int g1 = 0;
int g2 = 0;
int g3 = 0;
int g4 = 0;
int g5 = 0;
int g6 = 0;
void f1() {
  S1(g1);   // NON_COMPLIANT
  S1 g2();  // NON_COMPLIANT
  S1 g3;    // COMPLIANT[FALSE_POSITIVE]
  S1 g4{};  // COMPLIANT[FALSE_POSITIVE]
  S1 g5(1); // COMPLIANT[FALSE_POSITIVE]
  S1 g6{1}; // COMPLIANT[FALSE_POSITIVE]
}
@lcartey lcartey added Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low labels Dec 6, 2024
@lcartey lcartey moved this from Reported to Triaged in Coding Standards Public Development Board Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty-Medium A false positive or false negative report which is expected to take 1-5 days effort to address false positive/false negative An issue related to observed false positives or false negatives. Impact-Low
Projects
Development

No branches or pull requests

1 participant