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

A7-1-7: Avoid reporting the same expression or declaration in multiple template instantiations #383

Closed
lcartey opened this issue Oct 3, 2023 · 3 comments
Assignees
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 user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@lcartey
Copy link
Collaborator

lcartey commented Oct 3, 2023

Affected rules

  • A7-1-7

Description

In a template class or template function we may report the same logical expression in multiple template instantiations.

Example

template <typename T>
class Foo {
  void bar(T t) { t; } // COMPLIANT - but erroneously reported
};

void test() {
  Foo<int> i;
  Foo<float> f;
  i.bar(1);
  f.bar(1.0f);
}
@lcartey lcartey added 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 user-report Issue reported by an end user of CodeQL Coding Standards labels Oct 3, 2023
@rvermeulen rvermeulen self-assigned this Feb 8, 2024
@rvermeulen rvermeulen moved this from Triaged to In Progress in Coding Standards Public Development Board Feb 15, 2024
@rvermeulen
Copy link
Collaborator

Cannot reproduce an amended version of the test case (bar is private).
For each instantiation we get an ExprStmt for t in bar, however the location for each of those is the same and the query already excludes different ExprStmts with the same location.

@lcartey Is there more context that we can use to reproduce?

@lcartey
Copy link
Collaborator Author

lcartey commented Jun 26, 2024

Re-reviewing the original bug report I believe I misdiagnosed this issue - it is actually completely unrelated to templates.

A fuller reproduction case is as follows:

class Test {
public:
  friend constexpr void swap(Test &lhs, Test &rhs) noexcept { lhs.swap(rhs); }
  void swap(Test &other) noexcept;
};

void test_swap() {
  Test a1, a2;
  swap(a1, a2);
}

The query reports that the function swap is defined on the same line as the expression statement lhs.swap(rhs). Reviewing the AUTOSAR rule, I don't believe the intention is to report such cases - the rule itself does not mention functions either way, and it certainly does not make sense to report the function declaration in which an expression statement is declared as contravening in this case.

As the problem is distinctly different from this initial bug report, I'm closing this as "Doesn't reproduce" and opening a new issue here to track the function problem:
#628

@lcartey
Copy link
Collaborator Author

lcartey commented Jun 26, 2024

In debugging this issue, I identified a couple more problems with A7-1-7 and logged those separately:

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 user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Status: Closed (Duplicate)
Development

No branches or pull requests

3 participants