Skip to content

Missing -Wreturn-stack-address cases for lambda. #102050

@hokein

Description

@hokein
#include <algorithm>
#include <functional>

auto foo(int x) {
    return [&]() { return x + 1; }; // good, give a warning.
}
std::function<int()> foo2(int x) {
    return [&]() { return x + 1; }; // no warning
}

auto foo3(int x) {
    auto a = [&]() { return x + 1;};
    return a; // no warning.
}

https://godbolt.org/z/nfacaEfGM, it would be good to detect case 2 and case 3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerclang:temporal-safetyIssue/FR relating to the lifetime analysis in Clang (-Wdangling, -Wreturn-local-addr)false-negativeWarning doesn't fire when it shouldlambdaC++11 lambda expressions

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions