AutosarC++18_03-A16.2.3

All used include directives shall be explicitly stated

Required inputs: IR

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

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.