MISRA Discussion Forums
3-2-4 and pure virtual functions - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C++ (https://forum.misra.org.uk/forumdisplay.php?fid=18)
+--- Forum: MISRA C++:2008 rules (https://forum.misra.org.uk/forumdisplay.php?fid=19)
+---- Forum: 6.3 Basic concepts (C++) (https://forum.misra.org.uk/forumdisplay.php?fid=132)
+---- Thread: 3-2-4 and pure virtual functions (/showthread.php?tid=1614)



3-2-4 and pure virtual functions - Tobias Loose - 10-04-2022

Hi!

Rule 3-2-4 states:


Quote:An identifier with external linkage shall have exactly one definition.


This would also apply to pure virtual functions of abstract base classes. I have personally never seen anyone use that feature and gather from reading up about it that it is questionable design to supply definitions for those. In most cases, these functions would be empty and collide with rules about unused code anyway.

Was this intended or an oversight? I propose to add an exception for pure virtual functions.

Also, I propose to replace "An" with "All". Otherwise, it would be enough to add one variable somewhere and provide a definition for it.

Thanks!


RE: 3-2-4 and pure virtual functions - misra cpp - 12-04-2022

When this was written in 2008, we were a bit lax with our use of the terms 'identifier' and 'definition'. In the version we are proposing for the next version, this has become 'An entity shall have no more than one definition' - which is hopefully clearer.

The intension is that a pure virtual function satisfies this requirement