AutosarC++17_10-A7.1.6¶
The typedef specifier shall not be used
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
The typedef specifier can not be easily used for defining alias templates. Also, the typedef syntax makes the code less readable.
For defining aliases, as well as template aliases, it is recommended to use the using syntax instead of the typedef.
Note that active issues related to the using syntax are listed below, in the “See also” section.
Example
// $Id: A7-1-6.cpp 271687 2017-03-23 08:57:35Z piotr.tanski $ #include <cstdint> #include <type_traits> typedef std::int32_t (*fPointer1)(std::int32_t); // Non-compliant using fPointer2 = std::int32_t (*)(std::int32_t); // Compliant // template<typename T> // typedef std::int32_t (*fPointer3)(T); // Non-compliant - compilation error template <typename T> using fPointer3 = std::int32_t (*)(T); // Compliant
See Also
- C++ Core Guidelines [10]: T.43: Prefer using over typedef for defining aliases
- C++ Standard Core Language Active Issues, Revision 96 [17]: 1554. Access and alias templates.
- C++ Standard Core Language Defect Reports and Accepted Issues, Revision 96 [17]: 1558. Unused arguments in alias template specializations.
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
typedef_specifier |
The typedef specifier shall not be used. |
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.