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

Reply via email to