<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - False warning: address of stack memory associated with local"
href="http://llvm.org/bugs/show_bug.cgi?id=16548">16548</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>False warning: address of stack memory associated with local
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.3
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>dushistov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Here code:
#include <cstdio>
void f()
{
static const size_t buf_size = 30;
char fmt_buf[buf_size];
auto my_fmt_f = [&fmt_buf](int a, int b) -> char * {
snprintf(fmt_buf, buf_size, "AA %d BB %d CC\n", a, b);
return fmt_buf;
};
puts(my_fmt_f(10, 20));
puts(my_fmt_f(30, 2));
}
int main()
{
f();
return 0;
}
$ clang++ -Wall -std=c++11 return_stack_address.cpp
return_stack_address.cpp:9:10: warning: address of stack memory associated with
local variable 'fmt_buf' returned [-Wreturn-stack-address]
return fmt_buf;
^~~~~~~
1 warning generated.
I think that this is false warning, and for example g++ not generate warning on
this code, while it generate warning for example if
char *f()
...
return fmt_buf;</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>