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

Returning address of variable copied into lambda produces spurious warning. #17748

Closed
llvmbot opened this issue Sep 26, 2013 · 1 comment
Closed
Labels
bugzilla Issues migrated from bugzilla c++11 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Sep 26, 2013

Bugzilla Link 17374
Version 3.2
OS All
Reporter LLVM Bugzilla Contributor
CC @DougGregor

Extended Description

Given the following sample code:

int main()
{
int i;
auto f = =mutable->int*
{
return &i;
};

return 0;

}

The compiler reports "address of stack memory associated with local variable 'i' returned" for the 'i' in the lambda. That warning would be legitimate for a plain function but not for a lambda.

Note that this bug appears similar to bug #​16548 but it is not the same. Here, the variable is captured by value rather than by reference.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@wheatman
Copy link
Contributor

This was fixed between 3.4 and 3.5
https://godbolt.org/z/dvjTEWhjd

code

//compile with -std=c++11 -Wreturn-stack-address
int main()
{
    int i = 0;
    auto f = [=]()mutable->int*
    {
            return &i;
    };

    return 0;
}

old warning

<source>:7:21: warning: address of stack memory associated with local variable 'i' returned [-Wreturn-stack-address]
            return &i;
                    ^
1 warning generated.
Compiler returned: 0

@wheatman wheatman added the clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer label Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++11 clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

No branches or pull requests

2 participants