I noticed that header path resolving, to not including "#pragma once" header twice, isn't working by comparing full paths.
For example, if I have a file "dir/a.h":
#pragma once
//...
And "dir/a.cpp":
#include"dir/a.h"#include"a.h"
Then when I run cppcheck -I$PWD dir/a.cpp, cppcheck includes the "dir/a.h" twice - path resolving works, but fullpath comparing doesn't, so that the #pragma once comment doesn't avoid the header to be included twice.
I believe that the algorithm for #pragma once resolution should just be to compare the two absolute paths of the file.
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have found the place in the code that needed to be fixed(in simplecpp), and here is my rough fix that I'm sure that is not clean (uncomment commented lines to see the difference between absolute/non-absolute paths that are consider to be different):
I noticed that header path resolving, to not including "#pragma once" header twice, isn't working by comparing full paths.
For example, if I have a file "dir/a.h":
And "dir/a.cpp":
Then when I run
cppcheck -I$PWD dir/a.cpp
, cppcheck includes the "dir/a.h" twice - path resolving works, but fullpath comparing doesn't, so that the#pragma once
comment doesn't avoid the header to be included twice.I believe that the algorithm for
#pragma once
resolution should just be to compare the two absolute paths of the file.Thanks
I have found the place in the code that needed to be fixed(in simplecpp), and here is my rough fix that I'm sure that is not clean (uncomment commented lines to see the difference between absolute/non-absolute paths that are consider to be different):
You should probably open an issue/PR here: https://github.com/danmar/simplecpp/
Done: https://github.com/danmar/simplecpp/pull/362