[LLVMbugs] [Bug 13130] New: Clang does not issue a warning for self-initialized base class members

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jun 16 23:35:39 PDT 2012


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

             Bug #: 13130
           Summary: Clang does not issue a warning for self-initialized
                    base class members
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: fedorabugmail at yahoo.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


In the code below, the base class and derived class both have one member
variable. Both variables are set to themselves in the init list of the derived
class constructor. Clang gives a warning for the derived class member "field is
uninitialized when used here" but does not for the base class member. Since
this is essentially a self-assignmnet, I would expect Clang to issue a warning
for both variables. 


#include <stdio.h>
class base {
  public:
    base(int * value);
  protected:
    int * value;
};

base::base(int * value)
 : value(value){}

class derived : public base {
  private:
    //int * value2;
  public:
    derived();
    void print() {printf("Child value is %p : %p\n",value,(int*)0);}
};

derived::derived()
 : base(value){}  //Self-assignment but no warning

int main()
{
  derived thisChild;
  thisChild.print();
}

Clang sets value to zero in the code above. However if value2 is commented out,
value is not initialized.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list