Following scenario does not seem to be correct (using cppcheck 2.1 gui): Using " return (*this)(i, i);" causes
(error) Reference to temporary returned. [returnTempReference]
while using "return this->operator()(i, i);" does not.
As far as I know, the latter case is correct and no error should be issued.
#include <iostream> class Base { public: Base() : elements{1,2,3,4,5} { } double& operator()(unsigned int i, unsigned int j) { return elements[i+j]; } double& operator()(unsigned int i) { //return this->operator()(i, i); return (*this)(i, i); } double elements[5]; }; int main() { Base b; std::cout<<"b(0): "<<b(0)<<"\n"; }
Thanks! I can reproduce.. I have created ticket https://trac.cppcheck.net/ticket/9879
Log in to post a comment.
Following scenario does not seem to be correct (using cppcheck 2.1 gui):
Using " return (*this)(i, i);" causes
while using
"return this->operator()(i, i);"
does not.
As far as I know, the latter case is correct and no error should be issued.
Last edit: Fredrik Bondesson 2020-09-07
Thanks! I can reproduce.. I have created ticket https://trac.cppcheck.net/ticket/9879