This one produces the error:
struct Base { virtual auto get() -> int & = 0; }; struct A : public Base { int z = 42; auto get() -> int & override { return z; } auto getMore() -> int & { return get(); } }; int main() { A a; int &z = a.getMore(); ++z; }
But if you remove the Base struct like this, the error is gone (also removing just the override keyword gets rid of the error):
/*struct Base { virtual auto get() -> int & = 0; };*/ struct A /*: public Base*/ { int z = 42; auto get() -> int & /*override*/ { return z; } auto getMore() -> int & { return get(); } }; int main() { A a; int &z = a.getMore(); ++z; }
cppcheck: commit 62702a6 built with: make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes
$ cppcheck main.cpp Checking main.cpp ... main.cpp:8:41: error: Reference to temporary returned. [returnTempReference] auto getMore() -> int & { return get(); } ^
Thanks! I created https://trac.cppcheck.net/ticket/9811
Fixed for me in 48a6852.
Log in to post a comment.
This one produces the error:
But if you remove the Base struct like this, the error is gone (also removing just the override keyword gets rid of the error):
cppcheck: commit 62702a6
built with: make MATCHCOMPILER=yes FILESDIR=/usr/share/cppcheck HAVE_RULES=yes
Last edit: Andreas Grob 2020-07-17
Thanks! I created https://trac.cppcheck.net/ticket/9811
Fixed for me in 48a6852.