AutosarC++18_10-A16.2.3

An include directive shall be added explicitly for every symbol used in a file

Required inputs: IR

Rationale

All header files that define types or functions used in a file should be included explicitly.

The actual header to include depends on the specification of the library/component used.

Exceptions

Types defined via forward declarations do not violate this rule.

Example
// $Id: A16-2-3.hpp 319944 2018-05-21 09:00:40Z ilya.burylov $
    #ifndef HEADER_HPP
    #define HEADER_HPP

    #include <array>
    #include <cstdint>

    class B;     // Compliant - type B can be included using forward declaration

    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

allow_inclusion_through_own_header

allow_inclusion_through_own_header : bool = False

Allows the indirect inclusion through the header belonging to a compilation unit. Headers are considered corresponding to an implementation file, if they share the same basename. That is, an indirect inclusion of a symbol in file.cpp would be allowed via file.h. Further indirections are still forbidden.
 

internal_header_patterns

internal_header_patterns : set[str] = set()

Filename patterns for headers to be considered as internal, i.e., they should not be included directly but indirectly though another header.
 

internal_symbol_patterns

internal_symbol_patterns : set[str] = set()

Patterns for symbols to be considered as internal, i.e., they should not be included directly but indirectly though another header.