AutosarC++19_03-A3.1.1¶
It shall be possible to include any header file in multiple translation units without violating the One Definition Rule
Required inputs: IR
| Level | required |
|---|---|
| Target | architecture / design / implementation |
| Enforcement | automated |
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.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
external_function_definition_in_header |
External function definition in header file. |
None |
False |
external_static_field_def_in_header |
External definition in header file. |
None |
False |
external_variable_definition_in_header |
External variable definition in header file. |
None |
False |
internal_function_declaration_in_header |
Internal function declaration in header file. |
None |
False |
internal_function_definition_in_header |
Function definition in header file (with internal linkage). |
None |
False |
internal_static_field_def_in_header |
Definition in header file (with internal linkage). |
None |
False |
internal_variable_definition_in_header |
Variable definition in header file (with internal linkage). |
None |
False |
tentative_variable_definition_in_header |
Tentative variable definition in header file. |
None |
False |
Options¶
This rule shares the following common options: confidence, exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
accept_const_fields¶
accept_const_fields : bool = False
accept_const_variables¶
accept_const_variables : bool = True
find_non_external_function_declaration¶
find_non_external_function_declaration : bool = True
report_tentative_definitions¶
report_tentative_definitions : bool = False