Clang warning: ... stack memory associated with ... B returned [-Wreturn-stack-address] (warn_ret_stack_addr_ref)
Jump to navigation
Jump to search
Text |
(since 7.0)
(until 6.0) | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Type | Warning | ||||||||||||||
Category | Semantic Issue | ||||||||||||||
Internal Id | warn_ret_stack_addr_ref | ||||||||||||||
Active by Default | Yes | ||||||||||||||
Flags | -Wno-dangling (12 elements) -Wno-return-local-addr (3 elements) -Wno-return-stack-address (3 elements) | ||||||||||||||
Internal Message | %select{address of|reference to}0 stack memory associated with %select{local variable|parameter}2 %1 returned (since 7.0)%select{address of|reference to}0 stack memory associated with local variable %1 returned (until 6.0)
| ||||||||||||||
Regular Expression | (?:warning|error|fatal error)\: (?:address of|reference to) stack memory associated with (?:local variable|parameter) (.*?) returned \[(?:\-Werror,)?\-Wreturn\-stack\-address[^\]]*\]
| ||||||||||||||
First Commit | 2015-11-17 da7b27ff0b98 [Sema] Combine similar diagnostics using %select. NFC |
Description
Example
Flags | -xc++
|
|
---|---|---|
Source |
#include<iostream>
using namespace std;
int& f() {
int a = 10; // Local variable
return a; // Return reference to local variable
}
int main() {
int& b = f();
cout << b << endl;
return 0;
}
| |
Compiler Output |
<source>:6:12: warning: reference to stack memory associated with local variable 'a' returned [-Wreturn-stack-address] |
Clang Internals (17.0.6)
Git Commit Message
[Sema] Combine similar diagnostics using %select. NFC llvm-svn: 253315
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaInit.cpp (line 8257)
void Sema::checkInitializerLifetime(const InitializedEntity &Entity, Expr *Init) {
// ...
auto TemporaryVisitor = [&](IndirectLocalPath &Path, Local L, ReferenceKind RK) -> bool {
// ...
case LK_Return:
case LK_StmtExprResult:
if (auto *DRE = dyn_cast<DeclRefExpr>(L)) {
// ...
Diag(DiagLoc, diag::warn_ret_stack_addr_ref) << Entity.getType()->isReferenceType() << DRE->getDecl() << isa<ParmVarDecl>(DRE->getDecl()) << DiagRange;
Triggered in Clang Tests
This section lists all internal Clang test cases that trigger the diagnostic.
clang/test/CodeGen/pointer-to-int.c
- clang/test/CodeGen/pointer-to-int.c:11:10: warning: address of stack memory associated with local variable 'x' returned [-Wreturn-stack-address]