Returning the value of an `optional<T&>` parameter from a function triggers incorrect `-Wreturn-stack-address`
Open
clang:diagnostics
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
```c++
#include
int& test(std::optional optional) {
return *optional;
}
int main() {
int value = 42;
return test(value);
}
```
The bug happens with version 22. It works fine on trunk.
[Link to compiler explorer](https://compiler-explorer.com/z/nh3Y9aaaj)
Contributor guide
Research direction
Start by reproducing the C++ snippet in Compiler Explorer with version 22 and trunk, comparing the -Wreturn-stack-address diagnostics. Trace the compiler warning path for returning *optional and verify that the valid reference return no longer triggers the incorrect warning, matching trunk behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100