However this doesn't seem to work correctly. I have a method that returns a boost::array by value, and this results in the warning "error (returnDanglingLifetime): Returning pointer to local variable 'coords' that will be invalid when returning". If I change the boost::array to a std::array, no warning is generated.
Can anyone tell me the correct way to define that boost::array behaves like std::array?
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
$ cppcheck --library=std --library=library.xml test.cpp
Checking test.cpp ...
[test.cpp:8] -> [test.cpp:7] -> [test.cpp:8]: (error) Returning pointer to local variable 'c' that will be invalid when returning.
If I change the boost::array to a std::array, cppcheck doesn't report a warning.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not sure if you can inherit from stdArray. because it comes from a different file. maybe it works. I guess std.cfg is loaded first but I am not sure about that neither.
Does it work otherwise? For example does this code generate a warning:
void f(){
boost::array<int,5> a;
a[10]=0;//<- a error should be written
}
I would be highly interested in publishing a boost.cfg. At my work we use some boost utility functions also so I would probably add those.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have tested if the std.cfg is loaded before boost.cfg that i created locally. When only --library=boost is specified an error message is printed that stdArray is not known. But when --library=std --library=boost is specified the std.cfg is loaded before boost.cfg and stdArray is found. That corresponds with earlier observations i made. The std.cfg is normally one of the last library files that is loaded.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am also interested in boost.cfg as we use boost extensively at my work (though we are slowly transitioning to C++11 equivalents where possible). I would be willing to help with this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am also interested in boost.cfg as we use boost extensively at my work (though we are slowly transitioning to C++11 equivalents where possible). I would be willing to help with this.
I created a small boost.cfg file. please fill in some information. I will add some boost algorithm functions and maybe the boost property_tree somehow. that will cover most stuff that we have at my work.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I made a start this morning. I'm unsure what type of function definitions provide the most value (ie are most likely to improve the checking) so it's hard to know where to begin. I couldn't come up with anything meaningful for the boost features we use the most (bind, shared_ptr, mutex, lock_guard, ptime, make_shared).
Ideally you should be able to use --check-library.
Only 7000 warnings when run on our code base from work! But it does give some ideas for where to start. I'll take a look at boost::circular_buffer, unordered_set, and filesystem next. The string algorithms and ptree will be useful too.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've defined some math functions and constants, macros for the BOOST_TEST framework, and a couple of containers. This does introduce a dependency on std though.
Could you create a PR?
I guess the std dependency is ok.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for adding the initial version of this file to 1.87. Given that I haven't contributed to cppcheck before, what is the process for getting my library definitions added?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Not sure which information you exactly need.
Here is how i contribute:
I forked cppcheck and cloned it locally.
Regularly update the local repository with git pull upstream master.
Change some code / configuration file / ...
Create a branch for the Pull Request i want to make.
Commit the corresponding changes to this branch.
Push the branch to my forked repository at GitHub.
Create a Pull Request on GitHub based on the branch, it is automatically suggested for some time after the branch was pushed.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In my library file I have a definition for boost::array like this:
However this doesn't seem to work correctly. I have a method that returns a boost::array by value, and this results in the warning "error (returnDanglingLifetime): Returning pointer to local variable 'coords' that will be invalid when returning". If I change the boost::array to a std::array, no warning is generated.
Can anyone tell me the correct way to define that boost::array behaves like std::array?
Thanks!
Do you have a code snippet for this?
Library file:
Code snippet:
Cppcheck 1.86 output:
If I change the boost::array to a std::array, cppcheck doesn't report a warning.
I am not sure if you can inherit from stdArray. because it comes from a different file. maybe it works. I guess std.cfg is loaded first but I am not sure about that neither.
Does it work otherwise? For example does this code generate a warning:
I would be highly interested in publishing a
boost.cfg
. At my work we use some boost utility functions also so I would probably add those.I have tested if the std.cfg is loaded before boost.cfg that i created locally. When only
--library=boost
is specified an error message is printed that stdArray is not known. But when--library=std --library=boost
is specified the std.cfg is loaded before boost.cfg and stdArray is found. That corresponds with earlier observations i made. The std.cfg is normally one of the last library files that is loaded.Yes, that code generates the expected warning.
I am also interested in boost.cfg as we use boost extensively at my work (though we are slowly transitioning to C++11 equivalents where possible). I would be willing to help with this.
I created a small boost.cfg file. please fill in some information. I will add some boost algorithm functions and maybe the boost property_tree somehow. that will cover most stuff that we have at my work.
I made a start this morning. I'm unsure what type of function definitions provide the most value (ie are most likely to improve the checking) so it's hard to know where to begin. I couldn't come up with anything meaningful for the boost features we use the most (bind, shared_ptr, mutex, lock_guard, ptime, make_shared).
I've defined some math functions and constants, macros for the BOOST_TEST framework, and a couple of containers. This does introduce a dependency on std though.
https://github.com/StevePER/cppcheck/blob/master/cfg/boost.cfg
Ideally you should be able to use
--check-library
.yeah as far as I know you can't configure those meaningfully. That would be useful.
Last edit: Daniel Marjamäki 2018-12-14
Only 7000 warnings when run on our code base from work! But it does give some ideas for where to start. I'll take a look at
boost::circular_buffer
,unordered_set
, andfilesystem
next. The string algorithms and ptree will be useful too.Could you create a PR?
I guess the std dependency is ok.
https://trac.cppcheck.net/ticket/8908
I've added all the boost::constants, more containers, and functions from boost::filesystem.
Added boost::lexical_cast and endian conversion functions. I can't see anything else that I can add.
Thanks for adding the initial version of this file to 1.87. Given that I haven't contributed to cppcheck before, what is the process for getting my library definitions added?
Not sure which information you exactly need.
Here is how i contribute:
I forked cppcheck and cloned it locally.
Regularly update the local repository with
git pull upstream master
.Change some code / configuration file / ...
Create a branch for the Pull Request i want to make.
Commit the corresponding changes to this branch.
Push the branch to my forked repository at GitHub.
Create a Pull Request on GitHub based on the branch, it is automatically suggested for some time after the branch was pushed.
thanks!
as versat said.. best is to create some github pull requests.