This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][UninitializedObjectChecker] Explicit namespace resolution for inherited data members
ClosedPublic

Authored by Szelethus on Aug 17 2018, 8:57 AM.

Details

Summary

For the following example:

struct Base {
  int x;
};

// In a different translation unit

struct Derived : public Base {
  Derived() {}
};

For a call to Derived::Derived(), we'll receive a note that this->x is uninitialized. Since x is not a direct field of Derived, it could be a little confusing. This patch aims to fix this, as well as the case when the derived object has a field that has the name as an inherited uninitialized data member:

struct Base {
  int x; // note: uninitialized field 'this->Base::x'
};

struct Derived : public Base {
  int x = 5;
  Derived() {}
};

This patch is also meant as a conversation starter, as the way base classes were handled has been long debated.

Diff Detail

Event Timeline

Szelethus created this revision.Aug 17 2018, 8:57 AM
Szelethus edited the summary of this revision. (Show Details)Aug 17 2018, 10:05 AM
NoQ accepted this revision.Aug 17 2018, 12:13 PM
NoQ added inline comments.
lib/StaticAnalyzer/Checkers/UninitializedObject/UninitializedObjectChecker.cpp
114–115

Maybe just BaseClassT->getAsCXXRecordDecl()->getName()?

This revision is now accepted and ready to land.Aug 17 2018, 12:13 PM
Szelethus retitled this revision from [analyzer][UninitializedObjectChecker][WIP] Explicit namespace resolution for inherited data members to [analyzer][UninitializedObjectChecker] Explicit namespace resolution for inherited data members.Aug 21 2018, 5:15 AM
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.