Currently as far as I know, you can ask cppcheck to display in the warning message the file/line trace that called it. I'd like to have also the function name, but more importantly - the template variable assignment (and auto types resolutions) that caused the errors, both for the templates of a function and struct/class. Alternatively, do you know how to deduce which template instantiation had caused a particular warning?
thanks!
The following code yields false positive in the upstream cppcheck: #include <iostream> struct ostream_holder { explicit ostream_holder(std::ostream& os) : m_os(os) {} ostream_holder(const ostream_holder&) = default; std::ostream& m_os; }; template <typename T> std::ostream& operator<<(ostream_holder os_holder, const T& value) { os_holder << value; return os_holder.m_os; } The returned error: example.cpp:14:21: error: Reference to local variable returned. [returnReference] return os_holder.m_os; Even...
The file indexing in -plist-output output (used for formatting results in CodeChecker-friendly way) is sometimes set to 0, because the code reported the error didn't provide info about the indexing. For example, I get in the errors of ctunullpointer but inspecting the .plist file you see that the file index is set to 0, which results with CodeChecker not pointing to the right file on the stack call view of it. Here is a not-too-ugly patch I used locally (i.e. store in a static variable the input...
thanks!
cppcheck complains about dereferencing iterators in an array of iterators: #include <vector> std::vector<int>::const_iterator f() { const std::vector<int> v = {1, 2, 3, 4}; const std::vector<int>::const_iterator a[2] = { v.begin(), v.end() }; return *a[1]; } Yields the error: [test.cpp:7]: (error) The iterator 'a' is invalid before being assigned. Dereferencing or comparing it with another iterator is invalid operation.
The way cppcheck treat the "#include" pragma in preprocessing is as follows: 1. If the header is found in the relative or the include paths with the "-I" flag, then cppcheck includes it 2. Otherwise, it ignores this line and continues. The design of cppcheck as a textual checker, is that intentionally it doesn't want the user to specify the "-I" flag for the std and boost libraries, but rather use the "packaged library" flags, that is enabled by default to std, but is needed to be explicitly given...
Sadly this is the duplicated post, please visit the original post