The C+\+ Standard [ISO/IEC 14882-2003|AA. C++ References#ISO/IEC 14882-2003] "One definition rule" One Definition Rule (ODR) (Section 3.2) states that Wiki Markup
No translation unit shall contain more than one definition of any variable, function, class type, enumeration type or template.
Furthermore, paragraph 3 of said section states that:
Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required.
Wiki Markup |
---|
says: "No translation unit shall contain more than one definition of any variable, function, class type, enumeration type or template." Moreover, paragraph 3 says: "Every program shall contain exactly one definition of every non-inline function or object that is used in that program; no diagnostic required." Although it is possible to check that the ODR is complied with (see \[[Quinlan 06|AA. C++ References#Quinlan 06]\]), as of October 2006 we are not aware of any compilers that fully enforce the rule or even issue a diagnostic. The EDG [C++ Front End|https://www.edg.com/index.php?location=c_frontend] diagnoses a subset of violations of the ODR when compiling in export mode (a mode where the C++ {{export}} feature is enabled). As the paper by Quinlan et al. shows, failing to enforce the ODR enables a virtual function pointer attack, known as the VPTR [exploit|BB. Definitions#exploit]. This is where an object's virtual function table is corrupted so that calling a virtual function on the object results in malicious code being executed. See the paper by Quinlan et al. for more details. |
...