I am having issues like: style: Variable 'raii' is assigned a value that is never used. [unreadVariable] with our custom raii classes.
What information is cppcheck missing such that it would know not to warn for such cases? I did use --check-config to see if there were any missing includes. But it only lists various system includes not from my code.
I am using cppcheck 2.7.3.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
can you please create a small example that reproduce the false positive.
I would spontanously think that if cppcheck see that raii is a class that might have global side effects during destruction we should not write this warning.
Last edit: Daniel Marjamäki 2022-03-23
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There are several issues at play here.
Cppcheck emits a known false positive with auto, this is tracked here: https://trac.cppcheck.net/ticket/10505
Declaring the variable as RAII raii; in your example still yields a warning, because cppcheck sees the empty con/destructors. If you then just declare class RAII; (or the con/destructor) inside test, the warning disappears. I did not see any effect of using namespace, but I might be missing something.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I am having issues like:
style: Variable 'raii' is assigned a value that is never used. [unreadVariable]
with our custom raii classes.What information is cppcheck missing such that it would know not to warn for such cases? I did use
--check-config
to see if there were any missing includes. But it only lists various system includes not from my code.I am using cppcheck 2.7.3.
can you please create a small example that reproduce the false positive.
I would spontanously think that if cppcheck see that raii is a class that might have global side effects during destruction we should not write this warning.
Last edit: Daniel Marjamäki 2022-03-23
I worked on minimizing it and ended up with this:
The problem seem to be the
using namespace test;
, if I remove that and explicitly usetest::RAII()
the warning goes away.I ran it like this:
cppcheck --std=c++17 --enable=all raii.cpp
(The compiler are happy with both versions.)
It also reproduces at https://cppcheck.sourceforge.io/demo/
There are several issues at play here.
Cppcheck emits a known false positive with
auto
, this is tracked here: https://trac.cppcheck.net/ticket/10505Declaring the variable as
RAII raii;
in your example still yields a warning, because cppcheck sees the empty con/destructors. If you then just declareclass RAII;
(or the con/destructor) insidetest
, the warning disappears. I did not see any effect ofusing namespace
, but I might be missing something.I see, so I guess ticket 10505 is the main issue.
Regarding the namespace the original code above warns, but this one does not:
Hmm, with current head I do get a warning: