[LLVMbugs] [Bug 16504] New: False positive regarding lifetime extension with static references

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jul 1 04:53:17 PDT 2013


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: kremenek at apple.com
          Reporter: labath at google.com
                CC: klimek at google.com, llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130701/d8c84c7d/attachment.html>


More information about the llvm-bugs mailing list