No matter the order of --library the result is always the same. That's because all library definitions are stored as <name> <value> string in a std::set. So by alphabetical ordering the empty define in the above example always takes precedence.
From a user-perspective it would make more sense to either:
* throw an error if the same macro is defined with different values (currently that's only the case for identical name/value pairs), or
* define a clear precedence depending on the order of the libraries specified on the command line.
Personally, I would probably favor the second option. That would also allow the user to re-define some of the built-in defines, which is how I came across this.
-Frank
P.S.: If there is a consensus I might be able to provide a PR...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, not about this topic, but somehow related with the problem mentioned here. 5 days ago I opened a similar situation related with the loading of the macros in std.cfg and their colosion, but I had got no answer, could you please provide an answer there? https://sourceforge.net/p/cppcheck/discussion/general/thread/89612cfdd4/
Thanks
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Using cppcheck with multiple library configs that define the same macro results in some surprising results, in terms of which one takes precedence.
Consider the two following libraries:
and execute:
No matter the order of
--library
the result is always the same. That's because all library definitions are stored as<name> <value>
string in astd::set
. So by alphabetical ordering the empty define in the above example always takes precedence.From a user-perspective it would make more sense to either:
* throw an error if the same macro is defined with different values (currently that's only the case for identical name/value pairs), or
* define a clear precedence depending on the order of the libraries specified on the command line.
Personally, I would probably favor the second option. That would also allow the user to re-define some of the built-in defines, which is how I came across this.
-Frank
P.S.: If there is a consensus I might be able to provide a PR...
I thought we bail out on duplicated defines nowadays...
That's only for duplicates within the same
.cfg
IIRC.Maybe that was the intention, but it's not what the code does. You only get an error if the name and value of the
define
are identical.Hi, not about this topic, but somehow related with the problem mentioned here. 5 days ago I opened a similar situation related with the loading of the macros in
std.cfg
and their colosion, but I had got no answer, could you please provide an answer there?https://sourceforge.net/p/cppcheck/discussion/general/thread/89612cfdd4/
Thanks