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

            Bug ID: 16504
           Summary: False positive regarding lifetime extension with
                    static references
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified

$ cat a.cc
struct A {
};

void f() {
  static const A &a = A();
}

$ clang --analyze a.cc
a.cc:5:3: warning: Address of stack memory associated with temporary object of
type 'struct A' is still referred to by the global variable 'a' upon returning
to the caller. This will be a dangling reference
  static const A &a = A();
  ^                   ~~~
1 warning generated.

-----------

According to my understanding of C++, the above program is correct (albeit
surprising, but apparently people actually use patterns like this) and the
temporary will not get destroyed upon exiting the function. Therefore, the
analyzer should not produce a warning in this case.

-- 
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