Cppcheck is not good at detecting syntax errors. We pass through lots of strange stuff and try to handle it as good as possible. I want that the compiler is used to check the code first.
If we wrote strict syntax checks according to the C/C++ standard then Cppcheck would be much less useful.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
For a member function of a non-template class, the default arguments are allowed on the out-of-class definition, and are combined with the default arguments provided by the declaration inside the class body.
https://github.com/danmar/cppcheck/pull/3431/commits/d4ad1b7aa37e831ee6c98f03d168983cc6095231
I got some false detects from cppcheck when tried to add new check (10444)
Last edit: Absol 2021-09-02
and
how to do it ?
tok->strAt(2)
thanks 👍, but why it not writed in output? (if cppcheck known it)
Regarding your first problem: The warning can be avoided if the default argument is removed from the definition. See here.
But I need this argument, it more easy to use if using default argument value
Then put it on the declaration instead?
hmm.. I thought it was a syntax error to write the default value like that. there is some compiler that don't require it on the declaration?
and then got syntax error?
Cppcheck is not good at detecting syntax errors. We pass through lots of strange stuff and try to handle it as good as possible. I want that the compiler is used to check the code first.
If we wrote strict syntax checks according to the C/C++ standard then Cppcheck would be much less useful.
but why in my case cppcheck print error ? this is false.positive?
Last edit: Absol 2021-09-03
Why is the the default argument still on the definition?
definition or declaration? in first case it legal, and always been legally.
sorry if bad english)
You must have a class with the name
CheckOther
otherwise you can't have a functionCheckOther::IsSameName
.but it compiled and executed without any problem, you can write how i do to fix this error found by cppcheck?? this function defined in this class.
https://trac.cppcheck.net/ticket/10457
Fixing parser bugs is relatively high prio. Thanks!
maybe you can check also https://sourceforge.net/p/cppcheck/discussion/development/thread/763c0b98d2/?limit=25#69f6
it target to '{' token, it wrong?))
I was surprised also, but it is apparently legal.
https://en.cppreference.com/w/cpp/language/default_arguments
Clang and MSVC both accept the code in the ticket.
Also
also strange proposes
Last edit: Absol 2021-09-03