[llvm-bugs] [Bug 37086] New: scan-build doesn't detect unitianilized class members in copy constructor

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 11 03:05:06 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37086

            Bug ID: 37086
           Summary: scan-build doesn't detect unitianilized class members
                    in copy constructor
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: dcoughlin at apple.com
          Reporter: marzec.wojciech at gmail.com
                CC: llvm-bugs at lists.llvm.org

I wish to have a warning that some member in copy constructor/assignment
operator isn't initialized. 


#include <iostream>
using namespace std; 

struct B 
{

    int member;
    B() 
    {
        member =111;
    }
    B(B const & )
    {}
    B& operator=(B const & )
    { }

    void hello() const 
    {   
        cout << "member value " << member << "\n";
    }


};
struct D :  B 
{

    D(){}
}; 


int main()
{

    B* b1_ptr = new B; 
    b1_ptr->hello();
    B* b2_ptr = new B(*b1_ptr);    
    b2_ptr->hello();

}

Above code gives me output:

member value 111
member value 0

Scan-build generaly warns about reading of unitialized variables but in this
case it is initialized with 0 by compiler however users forgets to do copy of
value and he expects to have the same object. So in this case  the user should
be warn that he forgets to copy member value in copy constructor/assignment
operator. 

Such case is handled by lint and it is a gap for unsecure code could you
implement such checking also in scan-build?

-- 
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/20180411/56a777c3/attachment.html>


More information about the llvm-bugs mailing list