I hesitate to actually draft a Trac ticket. A class copy constructor is used in my project, and the result found suggested using an initializer list to populate various members. This broke the copy constructor, so I'm pretty confident this result suggestion is not correct.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
thanks for reporting. let's try to fix it. could you create a code example. I think the easiest approach would be that you bisect your code into a small example. It doesn't have to compile; if Cppcheck complains then I am happy.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
:) Sure, I'd be happy to. There was another issue I notice by chance, unrelated, that I can open another discussion about.
This result is an example of several within the same copy constructor: src\Tank.h|174|useInitializationList : performance : When an object of a class is created, the constructors of all member variables are called consecutively in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'controller' a value by passing the value to the constructor in the initialization list.|
You'll find the copy constructor under the two constructor methods. Tank( const Tank &t ) { } Line 174 points to "controller = t.controller;", and the other similar results pointed out several (not all) other copy lines in this copy constructor.
And in 'fixing' by utilizing an initializer list, the resulting crash seemed to indicate this was not an appropriate fix/result.
'Hope that helps.
Last edit: Glenn Storm 2020-05-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
is it open source? I do not understand why it would crash when moving it to an initializer list. is there something special about TankController? can you explain that?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Well, no, nothing special about TankController. And, as mentioned, there were around 12 other similar lines of "make use of an initialize list". I did and it crashed, and so I simply un-did. But, given your reaction. I'll revisit and report back.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I hesitate to actually draft a Trac ticket. A class copy constructor is used in my project, and the result found suggested using an initializer list to populate various members. This broke the copy constructor, so I'm pretty confident this result suggestion is not correct.
thanks for reporting. let's try to fix it. could you create a code example. I think the easiest approach would be that you bisect your code into a small example. It doesn't have to compile; if Cppcheck complains then I am happy.
:) Sure, I'd be happy to. There was another issue I notice by chance, unrelated, that I can open another discussion about.
This result is an example of several within the same copy constructor:
src\Tank.h|174|useInitializationList : performance : When an object of a class is created, the constructors of all member variables are called consecutively in the order the variables are declared, even if you don't explicitly write them to the initialization list. You could avoid assigning 'controller' a value by passing the value to the constructor in the initialization list.|
Points to this header file content:
You'll find the copy constructor under the two constructor methods. Tank( const Tank &t ) { } Line 174 points to "controller = t.controller;", and the other similar results pointed out several (not all) other copy lines in this copy constructor.
And in 'fixing' by utilizing an initializer list, the resulting crash seemed to indicate this was not an appropriate fix/result.
'Hope that helps.
Last edit: Glenn Storm 2020-05-27
is it open source? I do not understand why it would crash when moving it to an initializer list. is there something special about TankController? can you explain that?
Well, no, nothing special about TankController. And, as mentioned, there were around 12 other similar lines of "make use of an initialize list". I did and it crashed, and so I simply un-did. But, given your reaction. I'll revisit and report back.