Skip to content

Fixed #7331: Detect copy and move constructors with default parameters#1018

Merged
danmar merged 1 commit intocppcheck-opensource:masterfrom
Sulley38:copy-cons-default-args
Jan 7, 2018
Merged

Fixed #7331: Detect copy and move constructors with default parameters#1018
danmar merged 1 commit intocppcheck-opensource:masterfrom
Sulley38:copy-cons-default-args

Conversation

@Sulley38
Copy link
Copy Markdown
Contributor

This is an attempt to fix issue #7331.
Copy and move constructors can have additional trailing parameters provided that they all have default values. See copy ctors and move ctors.

My approach has been to move the copy/move constructor detection to a later stage in the symbol database construction. They're initially parsed as regular constructors and checked if copy/move after default values have been parsed. Suggestions welcome, of course 😇

Comment thread test/testsymboldatabase.cpp Outdated
ASSERT(ctor && ctor->retDef == 0);
}
{
GET_SYMBOL_DB("class Foo { Foo(Foo & & f, int default = 1, bool default = true); };");
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.

is there 2 parameters with the name "default" here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops! Fixed

@Sulley38 Sulley38 force-pushed the copy-cons-default-args branch 2 times, most recently from 81e7459 to 743bf07 Compare December 30, 2017 09:52
Comment thread lib/symboldatabase.cpp Outdated
{
// fill in class and struct copy/move constructors
for (std::list<Scope>::iterator scope = scopeList.begin(); scope != scopeList.end(); ++scope) {
if (scope->isClassOrStruct()) {
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.

I prefer that continue is used

Comment thread lib/symboldatabase.cpp Outdated

if (func->type == Function::eCopyConstructor ||
func->type == Function::eMoveConstructor)
scope->numCopyOrMoveConstructors++;
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.

how about zeroing numCopyOrMoveConstructors in this method. Can numCopyOrMoveConstructors be incremented only in the above condition?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

numCopyOrMoveConstructors is only incremented at this point, at it's initialized to zero in the constructor of Scope.
I don't think zeroing it is necessary, but I don't have a strong opinion against it either.

@Sulley38 Sulley38 force-pushed the copy-cons-default-args branch from 743bf07 to 58d0716 Compare January 6, 2018 14:27
@danmar
Copy link
Copy Markdown
Collaborator

danmar commented Jan 7, 2018

I accept this now. Thanks for this fix!!

@danmar danmar merged commit cfeea3d into cppcheck-opensource:master Jan 7, 2018
@Sulley38 Sulley38 deleted the copy-cons-default-args branch January 7, 2018 14:19
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.

2 participants