Skip to content

[clang-tidy] "bugprone-return-const-ref-from-parameter" - should consider *this as a parameter #140473

Open
@denzor200

Description

@denzor200

As I suppose this check is expected to show warning in A::getThis method:

struct A {
  const A& getThis() const{ return *this; };
};

But it didn't. Logically I don't see any difference between A::getThis method and getThis regular function like this:

const A& getThis(const A& a) { return a; };

But the alalizer thinks that there is a difference! And show warning only for getThis regular function.
The warning should also be provided for A::getThis method because the known lifetime issue is also actual for it:

const auto& a = A().getThis();
// dangling `a`

The full snippet here: https://godbolt.org/z/xb669s6f3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions