[LLVMbugs] [Bug 20138] New: Warning on vector push_back call of statically allocated object with programmer defined constructor or destructor

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Jun 26 14:10:37 PDT 2014


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

            Bug ID: 20138
           Summary: Warning on vector push_back call of statically
                    allocated object with programmer defined constructor
                    or destructor
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: kremenek at apple.com
          Reporter: linuxham at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

I'm having a hard time determining if this is a STL bug or a clang false
positive, but the following code example at bottom causes this warning:

$ clang++ --analyze test.cpp
In file included from test.cpp:1:
In file included from
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../include/c++/4.8/vector:63:
/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../include/c++/4.8/bits/stl_uninitialized.h:75:19:
warning: Forming reference to null
      pointer
                std::_Construct(std::__addressof(*__cur), *__first);
                                ^~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.

Code:

#include <vector>

class Foo
{
public:
//    ~Foo(){} // uncommenting causes warning
    Foo() {} // uncommenting causes warning
};

int main(void)
{
    std::vector<Foo> v;
    Foo f = Foo();
    v.push_back(f);

    return 0;
}

If both the programmer-defined constructor and destructor are commented out, no
warning is produced.  Filling the constructor and destructor with a simple
allocation and free of memory to an added private member still result in the
same warning.

-- 
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/20140626/e7b44b58/attachment.html>


More information about the llvm-bugs mailing list