Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 6.2.1 weak linkage
#1
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!
Reply
#2
We don't believe that __attribute__((weak)) is defined in  C++17, so any use must be part of a language extension, which is out of the scope of MISRA C++

However, if you are using such an extension and you are getting violation messages from your tools, then the expected behaviour of weak vs. strong attributes is a justification to deviate.

As far as "replaceable" functions are concerned, the standard explicitly permits you to replace these functions with a user supplied version. This is not considered an ODR violation.
Posted by and on behalf of
the MISRA C++ Working Group
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)