Add test cases for assign operators with default implementation#2767
Conversation
|
deleted, because this was the wrong direction for this investigation |
|
@danmar I added my new findings see above |
|
Ok maybe not I just saw the xml attribute |
|
Yes the token is ".".. well that is a very old decision that made more sense before we had the AST. I think we can consider using "->" someday again but if somebody wants to change it then it must be done carefully. |
d504ef7 to
bc993df
Compare
|
@danmar So I found the issue and indeed it was in the symboldatabase |
| Token::Match(closeParen, ") . %type% = default ;") || | ||
| Token::Match(closeParen, ") . %type% & = default ;") || | ||
| Token::Match(closeParen, ") . const %type% & = default ;") || | ||
| Token::Match(closeParen, ") . const %type% = default ;") || |
There was a problem hiding this comment.
@danmar I'm pretty sure this can be done in a better way right?
and it also does not cover all cases yet.
So I'm hoping I will get some help here, please.
There was a problem hiding this comment.
well a start could be:
Token::Match(closeParen, ") . const| %type% &| = default ;"))
but not sure if that is the ultimate solution, maybe we have some code to handle trailing return type and stuff..
There was a problem hiding this comment.
there is some copy/paste problems in the SymbolDatabase. Maybe we should have some utility function to parse function attributes . There is a loop in Function::Function below a comment // parse function attributes that looks promising. I am spontanously wondering if that code can be broken out and reused somehow.
But.. the Token::Match pattern I provided could be a quick fix I could merge that as a start.. if you add a proper test in TestSymbolDatabase also. And then anybody can look at the refactoring later in a separate PR.
There was a problem hiding this comment.
another way is to reuse Tokenizer::isFunctionHead.. something like:
const Token *endtok = mTokenizer->isFunctionHead(closeParent->link(), ";");
if (endtok && Token::simpleMatch(endtok->tokAt(-2), "= default ;"))
.....
.. well we have some options. I believe a small fix to start with, with a proper test and a Token::Match is a good first step.
As far as I see, isFunctionHead does not handle trailing return types but it's very important that it can handle those.
There was a problem hiding this comment.
Alright, thank you I will clean it up and add a proper test for this.
maybe I'll find the time tomorrow evening
bc993df to
716694c
Compare
|
@danmar So here you go. |
|
Have you been added to our AUTHORS file? If not, you deserve to have your name there. What name would you like to add there? |
|
@danmar Wow thank you for the merge and also to give me the honors to call my self a "cppcheck author" :-) |
👋 @danmar
Sorry to bother you again 🙃
So I have found another issue, and after cutting down my code this fails
with:
$ cppcheck --enable=all "foobar.cpp" Checking foobar.cpp ... foobar.cpp:0:0: error: Internal Error: Invalid syntax [cppcheckError] ^ foobar.cpp:0:0: note: Internal Error: Invalid syntax ^ foobar.cpp:0:0: note: Internal Error: Invalid syntax ^{ }instead ofdefaultworksdefaultinside the struct definition worksfoobar& foobar::operator=(const foobar&) = default;worksSo I added two test cases to reproduce the issue.
cppcheck failes here:
call comes from this function
CheckClass::constructors()and on line
147it is checked:So I wonder why the check for
cpp func.type == Function::eOperatorEqualSo the issue boils down that
func.functionScopeisnullptrCould you point me in a direction, is this more of a tokenizing issue?