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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to