28-02-2025, 09:33 AM
Dear MISRA group,
I have a question regarding the interpretation of the one-definition-rule in the presence of weak linkage (i.e. __attribute__((weak))).
In particular, is it considered a violation of the odr rule/rule 6.2.1 if a function with "strong" linkage "overrides" a function with "weak" linkage (as typically found in (standard) libraries)?
A special case within this discussion are global allocation and deallocation functions. The C++ standard calls them explicitly "replaceable".
Implementation-wise in any standard library I know, this is expressed by the weak linkage attribute.
Since the standard allows these few functions to be replaced explicitly, I conclude this does not constitute a violation of the one-definition-rule.
But how about any other weak-linkage function?
Thanks in advance!
I have a question regarding the interpretation of the one-definition-rule in the presence of weak linkage (i.e. __attribute__((weak))).
In particular, is it considered a violation of the odr rule/rule 6.2.1 if a function with "strong" linkage "overrides" a function with "weak" linkage (as typically found in (standard) libraries)?
A special case within this discussion are global allocation and deallocation functions. The C++ standard calls them explicitly "replaceable".
Implementation-wise in any standard library I know, this is expressed by the weak linkage attribute.
Since the standard allows these few functions to be replaced explicitly, I conclude this does not constitute a violation of the one-definition-rule.
But how about any other weak-linkage function?
Thanks in advance!