AutosarC++19_03-M3.2.2¶
The One Definition Rule shall not be violated
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Violation of the One Definition Rule ([1] §3.2) leads to undefined behaviour. In general, this means that the program shall contain exactly one definition of every non-inline function or object.
Additionally:
- The definitions of a type shall consist of the same sequence of tokens, and;
- The definitions of a template shall consist of the same sequence of tokens, and;
- The definitions of an inline function shall consist of the same sequence of tokens.
Note that for the purposes of this rule, typedefs shall be treated as types.
Example
// file a.cpp
struct S1
{
int32_t i;
}; struct S2
{
int32_t i;
};
// file b.cpp
struct S1
{
int64_t i;
}; // Non-compliant – token sequence different
struct S2
{
int32_t i;
int32_t j;
}; // Non-compliant - token sequence different
Note
For legal reasons, this rule’s description is not part of the public documentation.