AutosarC++18_03-A16.2.3¶
All used include directives shall be explicitly stated
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | non-automated |
Rationale
All header files that define types used in a file should be included explicitly. Relying on inclusion dependencies of other header files makes the code more difficult to maintain.
Note that in header files some include directives could be easily replaced with forward declarations.
Example
// $Id: A16-2-3.hpp 289436 2017-10-04 10:45:23Z michal.szczepankiewicz $
#ifndef HEADER_HPP
#define HEADER_HPP
#include <array>
#include <cstdint>
class B; // Compliant - type B can be included using forward declaration
// std::into
// the header file
class OutOfRangeException
: public std::out_of_range // Non-compliant - <stdexcept> which defines
// out_of_range included
// implicitly through <array>
{
public:
using std::out_of_range::out_of_range;
};
class A {
public:
// Interface of class A
private:
std::array<std::uint32_t, 10>
mArray; // Compliant - <array> included explicitly
B *mB;
std::int32_t mX; // Compliant - <cstdint> included explicitly
};
#endif
See Also
- none
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
missing_include |
Explicit include directive for symbol ‘{}’ is missing. |
None |
False |
missing_include_macro |
Explicit include directive for macro ‘{}’ is missing. |
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
allow_inclusion_through_own_header¶
allow_inclusion_through_own_header : bool = False
internal_header_patterns¶
internal_header_patterns : set[str] = set()
internal_symbol_patterns¶
internal_symbol_patterns : set[str] = set()