Skip to content

Fix couple issues with missing operatorEqVarError#4576

Merged
danmar merged 2 commits intocppcheck-opensource:mainfrom
gerboengels:Fix_couple_issues_with_missing_operatorEqVarError
Nov 5, 2022
Merged

Fix couple issues with missing operatorEqVarError#4576
danmar merged 2 commits intocppcheck-opensource:mainfrom
gerboengels:Fix_couple_issues_with_missing_operatorEqVarError

Conversation

@gerboengels
Copy link
Copy Markdown
Contributor

For check operatorEqVarError (members variables missing in an operator=), I cppcheck bails out when a member function without a body is encountered, reasoning that that function might initialize some/all member variables.

However, I feel it bails out a bit too soon:

  • when such a function is const or static, it will probably not initialize member variables (although member variables could be mutable and thus be initialized in a const function; and a static function could be passed *this to initialize members, although this latter case isn't any different than calling any free function, in which case currently cppcheck doesn't bail out).
  • when operator= of a base class is called, I think it is fair to say the base class will initialize its own members (and of its subsequent base classes), but it shall not initialize members of the current object (although it is possible via a virtual function call, but then why are you implementing operator= when the base class takes care of it?)

Maybe some of these cases should be marked as inconclusive? I didn't yet look into that...

@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Nov 5, 2022

This looks reasonable. Let's try it. You can check the diff here in a couple of days:
http://cppcheck1.osuosl.org:8000/diff.html
check what the operatorEqVarError diff is.

@danmar danmar merged commit d7a8f7f into cppcheck-opensource:main Nov 5, 2022
Comment thread lib/checkclass.cpp
for (const Type::BaseInfo& i : scope->definedType->derivedFrom) {
const Type *derivedFrom = i.type;

assignAllVarsVisibleFromScope(usageList, derivedFrom->classScope);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like derivedFrom needs to be checked for nullptr, see http://cppcheck1.osuosl.org:8000/crash.html

@gerboengels gerboengels deleted the Fix_couple_issues_with_missing_operatorEqVarError branch November 11, 2022 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants