produces an unusedScopedObject message. Why? The language requires you to write code like this. The fact that the exception object is moved into somewhere magic and then deleted isn't really important.
Could this message be switched off for objects constructed and promptly thrown?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I also observe in our rather large codebase many unusedScopedObject messages. They started to occur months ago.
I bisected it in cppcheck trunk. It occurs since git commit:
sha1 id: 4c1c506d2153c8719cbccd0487bfecdc45e8167a
'#11472 FP return TempReference with cast and scope operator (#4676)'
chrchr-github
2023-01-02 22:13:56 CET
It has nothing to do with throw. Rather it looks like it is triggered when we return calling e.g. a ctor fully qualified with leading ::
This sort of code:
produces an unusedScopedObject message. Why? The language requires you to write code like this. The fact that the exception object is moved into somewhere magic and then deleted isn't really important.
Could this message be switched off for objects constructed and promptly thrown?
Which version are you using? Can you post a minimal example?
usually we should not warn if you throw the object.
a minimal example would be nice.
wild guess: is there an override of throw in some header:
I also observe in our rather large codebase many unusedScopedObject messages. They started to occur months ago.
I bisected it in cppcheck trunk. It occurs since git commit:
sha1 id: 4c1c506d2153c8719cbccd0487bfecdc45e8167a
'#11472 FP return TempReference with cast and scope operator (#4676)'
chrchr-github
2023-01-02 22:13:56 CET
It has nothing to do with throw. Rather it looks like it is triggered when we return calling e.g. a ctor fully qualified with leading ::
A minimal example triggering the message:
Hope this helps. Thanks in advance. I like cppcheck a lot. Kudos to Daniel Marjamäki and the other maintainers.
Sorry, not been able to check for a couple of days. I'm using cppcheck 2.10.3 (as provided by codacy)
Looks like the previous poster is having the same problems as I am, and I omitted to include the :: in my original example, so
would be a better example. Possibly
might be necessary.
Although having seen the prior post, does look like I needed the :: at the start
Last edit: T Tanner 2023-08-13
Thanks for reporting, fixed by https://github.com/danmar/cppcheck/pull/5321
Thank you!
I can confirm this fix. Thank you.
Caveat: The git-commit
sha1 id: 53714556066c7d9d83eff0af046e26fcf6da56c5
'optimized pipe writing/reading..'
Oliver Stöneberg
2023-08-13 11:52 CEST
renders my cppcheck unusable when called from the codeblocks ide. I have reverted just that for now.