Rule A3-1-1 (required, architecture / design / implementation,automated)

It shall be possible to include any header file in multiple translation units without violating the One Definition Rule.

Rationale

A header file is a file that holds declarations used in more than one translation unit and acts as an interface between separately compiled parts of a program. A header file often contains classes, object declarations, enums, functions, inline functions, templates, typedefs, type aliases and macros.

In particular, a header file is not supposed to contain or produce definitions of global objects or functions that occupy storage, especially objects that are not declared “extern” or definitions of functions that are not declared “inline”.

Example

//% $Id: A3-1-1.hpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $ #include <cstdint> void F1(); // Compliant extern void F2(); // Compliant void F3() { } // Non-compliant static inline void F4() { } // Compliant template <typename T> void F5(T) { } // Compliant std::int32_t a; // Non-compliant extern std::int32_t b; // Compliant constexpr static std::int32_t c = 10; // Compliant namespace ns { constexpr static std::int32_t d = 100; // Compliant const static std::int32_t e = 50; // Compliant static std::int32_t f; // Non-compliant static void F6() noexcept; // Non-compliant }

See also

MISRA C++ 2008 [7]: Rule 3-1-1 It shall be possible to include any header file in multiple translation units without violating the One Definition Rule.