AutosarC++17_03-A2.11.3

A “user-defined” type name shall be a unique identifier within a namespace

Required inputs: IR

Rationale

Reusing a user-defined type name, either as another type or for any other purpose, may lead to developer confusion. The user-defined type name shall not be duplicated anywhere in the project, even if the declaration is identical. The term user-defined type is defined as follows: - class - struct - union - enumeration - typedef / using

Example
//% $Id: A2-11-3.cpp 272338 2017-03-28 08:15:01Z piotr.tanski $
#include <cstdint>
class Type {};
// struct Type { }; // Non-compliant, Type name reused
// enum class Type : std::int8_t { }; // Non-compliant, Type name reused
See Also
  • MISRA C++ 2008 [6]: required 2-10-4 A class, union or enum name (including qualification, if any) shall be a unique identifier.
  • JSF December 2005 [7]: 4.15 AV Rule 135 Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that identifier.
  • HIC++ v4.0 [8]: 2.4.1 Ensure that each identifier is distinct from any other visible identifier

Possible Messages

Key

Text

Severity

Disabled

composite_defined_multiple_times

Composite type has multiple definitions.

None

False

enum_defined_multiple_times

Enumeration type has multiple definitions.

None

False

reused_tag

Tag name reused.

None

False

reused_typedef

Typedef name reused.

None

False

Options

check_types_only_with_external_linkage

check_types_only_with_external_linkage : bool = False

Whether the types should only be checked when they have external linkage.
 

tolerate_macros

tolerate_macros : bool = False

Whether #define and #undef using the typedef's name is allowed.
 

tolerate_typedef

tolerate_typedef : bool = False

Whether a typedef to the tag may have the same name.
 

tolerate_typedefed_entity

tolerate_typedefed_entity : bool = False

Whether the entity forming the typedef's underlying type can have the same name.