c++ - Misleading performance warning for auto_ptr type passed by value -
i'm checking 1 of projects cppcheck 1.75, , code (reduced clarity):
class tjob { public: tjob(std::auto_ptr<itask> task); // ... private: std::auto_ptr<itask> m_task; }; tjob::tjob( std::auto_ptr<itask> task // <-- here performance warning ): m_task(task) { trace("tjob ctr"); }
i'm getting new performance warning:
id: passedbyvalue
summary: function parameter 'task' should passed reference.
message: parameter 'task' passed value. passed (const) reference faster , recommended in c++.
which false positive. in opinion it's bug, because following suggestion leads serious bug[1], maybe there switch missed set, or template can provide declare ownership passed auto_ptr
?
i searched web , found far cppcheck incorporates checks check invalid usage of stl, example
- using auto pointer (auto_ptr)
i'm aware, auto_ptr
isn't best choice wouldn't same unique_ptr
? 2 checks interfere here?
besides using inline supression, possible suppress warnings cases?
edit: added footnote.
[1] there no serious bug, misunderstanding using std::auto_ptr
. somehow mixed compile-time run-time semantics: ownership isn't passed compile-time magic, rather @ runtime invoking "copy" constructor.
it has correctly detected passing value copy constructor when pass reference , amortise 1 of copies. optimiser fix 'issue' there not real need rely on it.
i expression of interface preferable in auto_ptr's case because tells caller taking pointer, core issue auto_ptr bad citizen (can left in invalid state copy operation), why deprecated.
Comments
Post a Comment