[LLVMbugs] [Bug 16548] New: False warning: address of stack memory associated with local

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 5 09:27:56 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16548

            Bug ID: 16548
           Summary: False warning: address of stack memory associated with
                    local
           Product: clang
           Version: 3.3
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dushistov at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

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;

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130705/056e873a/attachment.html>


More information about the llvm-bugs mailing list