AutosarC++18_03-A7.1.9¶
A class, structure, or enumeration shall not be declared in the definition of its type
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
Combining a type definition with a declaration of another entity can lead to readability problems and can be confusing for a developer.
Example
// $Id: A7-1-9.cpp 305629 2018-01-29 13:29:25Z piotr.serwa $
#include <cstdint>
enum class DIRECTION { UP, DOWN } dir; // non-compliant
class Foo {
public:
enum class ONE { AA, BB }; // compliant
static constexpr enum class TWO { CC, DD } sVar = TWO::CC; // non-compliant
static constexpr ONE sVar2 = ONE::AA; // compliant
};
struct Bar {
std::uint32_t a;
} barObj; // non-compliant
struct Bar2 {
std::uint32_t a;
} bar2Obj, *bar2Ptr; // non-compliant, also with A7-1-7
struct Foo2 {
std::uint32_t f;
};
Foo2 foo2Obj; // compliant
See Also
- JSF December 2005 [7]: AV Rule 141: A class, structure, or enumeration will not be declared in the definition of its type.
- C++ Core Guidelines [10]: C.7: Don’t define a class or enum and declare a variable of its type in the same statement.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
type_defined_in_declaration |
Type defined in declaration. |
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
This rule has no individual options.