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

M7-5-1: Class members are considered as **automatic** variables #805

Open
nbusser-sr opened this issue Nov 29, 2024 · 1 comment
Open

M7-5-1: Class members are considered as **automatic** variables #805

nbusser-sr opened this issue Nov 29, 2024 · 1 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-High user-report Issue reported by an end user of CodeQL Coding Standards

Comments

@nbusser-sr
Copy link

nbusser-sr commented Nov 29, 2024

Affected rules

  • M7-5-1

Rule 7–5–1

A function shall not return a reference or a pointer to
an automatic variable (including parameters), defined
within the function

Description

When a function returns a reference to a class member, this class member is wrongly considered as an automatic variable.

Example

class M7_5_1 {
    private:
      /// Variable to be referenced
      std::uint32_t val_;

    public:
    /// Triggers M7_5_1
    std::uint32_t& M7_5_1() noexcept {
      return val_;
    }
}
@nbusser-sr nbusser-sr added the false positive/false negative An issue related to observed false positives or false negatives. label Nov 29, 2024
@nbusser-sr nbusser-sr changed the title M5-7-1: Class members are considered as **automatic** variables M7-5-1: Class members are considered as **automatic** variables Nov 29, 2024
@lcartey lcartey added Difficulty-Low A false positive or false negative report which is expected to take <1 day effort to address Impact-High user-report Issue reported by an end user of CodeQL Coding Standards labels Dec 10, 2024
@lcartey lcartey moved this from Reported to Triaged in Coding Standards Public Development Board Dec 10, 2024
@lcartey
Copy link
Collaborator

lcartey commented Dec 10, 2024

Thanks! This issue was introduced during some refactoring for MISRA C++ 2023. The problem is that the query refers to Variable instead of StackVariable, so no longer considers locality. This should be a straightforward fix, along with augmenting our test cases.

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-High user-report Issue reported by an end user of CodeQL Coding Standards
Projects
Development

No branches or pull requests

2 participants