Fixed #7331: Detect copy and move constructors with default parameters#1018
Merged
danmar merged 1 commit intocppcheck-opensource:masterfrom Jan 7, 2018
Merged
Conversation
danmar
reviewed
Dec 29, 2017
| ASSERT(ctor && ctor->retDef == 0); | ||
| } | ||
| { | ||
| GET_SYMBOL_DB("class Foo { Foo(Foo & & f, int default = 1, bool default = true); };"); |
Collaborator
There was a problem hiding this comment.
is there 2 parameters with the name "default" here?
81e7459 to
743bf07
Compare
danmar
reviewed
Jan 2, 2018
| { | ||
| // fill in class and struct copy/move constructors | ||
| for (std::list<Scope>::iterator scope = scopeList.begin(); scope != scopeList.end(); ++scope) { | ||
| if (scope->isClassOrStruct()) { |
Collaborator
There was a problem hiding this comment.
I prefer that continue is used
danmar
reviewed
Jan 2, 2018
|
|
||
| if (func->type == Function::eCopyConstructor || | ||
| func->type == Function::eMoveConstructor) | ||
| scope->numCopyOrMoveConstructors++; |
Collaborator
There was a problem hiding this comment.
how about zeroing numCopyOrMoveConstructors in this method. Can numCopyOrMoveConstructors be incremented only in the above condition?
Contributor
Author
There was a problem hiding this comment.
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.
…h default parameters
743bf07 to
58d0716
Compare
Collaborator
|
I accept this now. Thanks for this fix!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 😇