Skip to content

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

Closed
@nbusser-sr

Description

@nbusser-sr

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_;
    }
}

Metadata

Metadata

Assignees

Labels

Difficulty-LowA false positive or false negative report which is expected to take <1 day effort to addressImpact-Highfalse positive/false negativeAn issue related to observed false positives or false negatives.user-reportIssue reported by an end user of CodeQL Coding Standards

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions