Qa Misra Compliance - Misra Cppautosar
Qa Misra Compliance - Misra Cppautosar
MISRA C++:2008
AUTOSAR C++14
QA Systems GmbH
powered by AbsInt Angewandte Informatik GmbH
CONTACT:
QA Systems GmbH
support@qa-systems.com
www.qa-systems.com
www.qa-systems.de/tools/qa-misra/
COPYRIGHT NOTICE:
© QA Systems GmbH
The product name QA-MISRA is a registered trademark of QA Systems GmbH. "MISRA" and "MISRA C" are
registered trademarks owned by The MISRA Consortium Ltd., held on behalf of the MISRA Consortium.
QA-MISRA is an independent tool of QA Systems and is not associated with the MISRA Consortium.
All rights reserved. This document, or parts of it, or modified versions of it, may not be copied, reproduced
or transmitted in any form, or by any means, or stored in a retrieval system, or used for any purpose,
without the prior written permission of QA Systems GmbH.
LIMITATION OF LIABILITY:
Every effort has been taken in manufacturing the product supplied and drafting the accompanying docu-
mentation.
QA Systems GmbH makes no warranty or representation, either expressed or implied, with respect to the
software, including its quality, performance, merchantability, or fitness for a particular purpose. The entire
risk as to the quality and performance of the software lies with the licensee.
Because software is inherently complex and may not be completely free of errors, the licensee is advised to
verify his work where appropriate. In no event will QA Systems GmbH be liable for any damages whatsoever
including – but not restricted to – lost revenue or profits or other direct, indirect, special, incidental, cover,
or consequential damages arising out of the use of or inability to use the software, even if advised of the
possibility of such damages, except to the extent invariable law, if any, provides otherwise.
QA Systems GmbH also does not recognize any warranty or update claims unless explicitly provided for
otherwise in a special agreement.
www.absint.com/known-issues/qa-misra/23.10.md
2 QA Systems GmbH
Contents
1 Introduction 4
1.1 Terms and Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 MISRA C++:2008 6
3 AUTOSAR C++14 22
QA-MISRA is a static analyzer that checks for violations of coding guidelines such as MISRA. It supports
the MISRA-C:2004, MISRA C:2012, MISRA C++:2008, AUTOSAR C++14, ISO/IEC TS 17961:2013, CERT, JSF AV
C++, and CWE rule sets, as well as rules for coding style and thresholds for code metrics.
If not stated otherwise for a specific set of guidelines, the degree of rule support is classified as follows.
fully checked A rule is fully checked (FC) if the checks adhere exactly to the rule text and the analysis
will never miss a rule violation. For fully checked rules, absence of alarms means the tool can prove the
absence of violations of this rule. False alarms may be issued.
This degree of support may be raised to fully checked + exact (FC+E) if the absence of false alarms can be
guaranteed.
partially checked A rule is partially checked (PC) if the checks either check only some aspects or a
(simplifying) reformulation of the rule (text) and/or the rule may miss rule violations. For partially
checked rules, absence of alarms does not imply absence of rule violations. False alarms may be issued.
This degree of support may be raised to partially checked + soundly supported (PC + S) if activating Astrée’s
semantic analysis underpins the rule check by issuing semantic alarms for violations of the rule and
by proving the absence of violations of some aspects of the rule or if the analyzer’s frontend implicitly
checks some aspects of the rule.
4 QA Systems GmbH
Chapter 1: Introduction
1.1 Terms and Definitions
(soundly) supported A rule is classified as (soundly) supported (S) if there are no dedicated checks, but
an analysis run may produce evidence whether or not the rule is broken. This compliance level may
require that the user provides appropriate analysis stubs.
For example
• the rule No reliance shall be placed on undefined or unspecified behavior. (MISRA-C:2004, rule 1.2) is
supported by Astrée because Astrée reports undefined and unspecified behavior.
• the rule All code shall conform to ISO/IEC 14882:2003 "The C++ Standard Incorporating Technical
Corrigendum 1" MISRA C++:2008, rule 1.0.1) is supported because the analyzer’s frontend reports
unsupported compiler-specific language extensions.
not checked A rule is not checked (NC) if there are no dedicated checks and checking the rule is not
supported by the analyzer.
Coding guideline checks can be executed with or without runtime error analysis. Coupling QA-MISRA
with Astrée’s runtime error analysis can raise the degree to which a coding guideline is supported.
The following table shows the degree of rule support for each rule assuming no coupling. Detailed
information on the degree of support when coupled with Astrée can be found in the dedicated a3 for
C/C++ Compliance documentation.
Coding guideline checks can be executed with or without runtime error analysis. Coupling QA-MISRA
with Astrée’s runtime error analysis can raise the degree to which a coding guideline is supported.
The following table shows the degree of rule support for each rule assuming no coupling. Detailed
information on the degree of support when coupled with Astrée can be found in the dedicated a3 for
C/C++ Compliance documentation.
In total, 189 rules of the rule set – i. e. 82% of all 228 rules – are checked:
Violations of this rule are reported for code that cannot be reached by
the analyzer. Such code is definitely unreachable except if the analysis
terminated prematurely because of an error. It cannot be guaranteed
that all unreachable code is reported.
0.1.4 A project shall not contain non-volatile POD variables having only FC+E
one use.
0.1.7 The value returned by a function having a non-void return type FC+E
that is not an overloaded operator shall always be used.
0.1.8 All functions with void return type shall have external side ef- NC
fect(s).
6 QA Systems GmbH
Chapter 2: MISRA C++:2008
. . . continued
General Support
1.0.1 All code shall conform to ISO/IEC 14882:2003 "The C++ Standard S
Incorporating Technical Corrigendum 1".
This rule applies to the used compiler and cannot be checked at the
source code level.
2.2.1 The character set and the corresponding encoding shall be docu- NC
mented.
2.7.1 The character sequence /* shall not be used within a C-style com- FC+E
ment.
2.7.2 Sections of code shall not be "commented out" using C-style com- NC
ments.
2.7.3 Sections of code should not be "commented out" using C++ com- NC
ments.
2.10.4 A class, union or enum name (including qualification, if any) shall FC+E
be a unique identifier.
2.13.2 Octal constants (other than zero) and octal escape sequences FC+E
(other than "\0") shall not be used.
2.13.5 Narrow and wide string literals shall not be concatenated. FC+E
8 QA Systems GmbH
Chapter 2: MISRA C++:2008
. . . continued
3.1.3 When an array is declared, its size shall either be stated explicitly FC+E
or defined implicitly by initialization.
3.2.3 A type, object or function that is used in multiple translation units FC+E
shall be declared in one and only one file.
3.2.4 An identifier with external linkage shall have exactly one defini- PC
tion.
3.3.2 If a function has internal linkage then all re-declarations shall FC+E
include the static storage class specifier.
3.9.1 The types used for an object, a function return type, or a function PC
parameter shall be token-for-token identical in all declarations
and re-declarations.
3.9.2 Typedefs that indicate size and signedness should be used in place PC
of the basic numerical types.
Only use of typedefs is checked, not whether their names indicate size
and signedness. This rule check is supported by Astrée’s semantic anal-
ysis: Astrée reports overflows resulting from incorrect assumptions
about the size/signedness of numerical types.
4.5.1 Expressions with type bool shall not be used as operands to built- FC+E
in operators other than the assignment operator =, the logical
operators &&, ||, !, the equality operators == and !=, the unary &
operator, and the conditional operator.
. . . continued
4.5.2 Expressions with type enum shall not be used as operands to FC+E
built-in operators other than the subscript operator [ ], the assign-
ment operator =, the equality operators == and !=, the unary &
operator,and the relational operators <, <=, >, >=.
4.5.3 Expressions with type (plain) char and wchar_t shall not be used FC+E
as operands to built-in operators other than the assignment oper-
ator =, the equality operators == and !=, and the unary & operator.
4.10.2 Literal zero (0) shall not be used as the null-pointer-constant. FC+E
Expressions Support
5.0.1 The value of an expression shall be the same under any order of PC
evaluation that the standard permits.
5.0.4 An implicit integral conversion shall not change the signedness FC+E
of the underlying type.
5.0.9 An explicit integral conversion shall not change the signedness FC+E
of the underlying type of a cvalue expression.
5.0.10 If the bitwise operators ~ and << are applied to an operand with FC+E
an underlying type of unsigned char or unsigned short, the result
shall be immediately cast to the underlying type of the operand.
5.0.11 The plain char type shall only be used for the storage and use of FC+E
character values.
10 QA Systems GmbH
Chapter 2: MISRA C++:2008
Expressions Support
. . . continued
5.0.12 signed char and unsigned char type shall only be used for the FC+E
storage and use of numeric values.
5.0.14 The first operand of a conditional-operator shall have type bool. FC+E
5.0.16 A pointer operand and any pointer resulting from pointer arith- NC
metic using that operand shall both address elements of the same
array.
5.0.18 >, >=, <, <= shall not be applied to objects of pointer type, except NC
where they point to the same array.
5.0.19 The declaration of objects shall contain no more than two levels FC+E
of pointer indirection.
5.2.2 A pointer to a virtual base class shall only be cast to a pointer to FC+E
a derived class by means of dynamic_cast.
5.2.3 Casts from a base class to a derived class should not be performed FC+E
on polymorphic types.
5.2.4 C-style casts (other than void casts) and functional notation casts FC+E
(other than explicit constructor calls) shall not be used.
5.2.5 A cast shall not remove any const or volatile qualification from FC+E
the type of a pointer or reference.
5.2.6 A cast shall not convert a pointer to a function to any other pointer FC+E
type, including a pointer to function type.
Expressions Support
. . . continued
5.2.8 An object with integer type or pointer to void type shall not be FC+E
converted to an object with pointer type.
5.2.9 A cast should not convert a pointer type to an integral type. FC+E
5.2.10 The increment (++) and decrement (--) operators should not be FC+E
mixed with other operators in an expression.
5.2.11 The comma operator, && operator and the || operator shall not FC+E
be overloaded.
5.2.12 An identifier with array type passed as a function argument shall FC+E
not decay to a pointer.
5.3.1 Each operand of the ! operator, the logical && or the logical || FC+E
operators shall have type bool.
5.3.2 The unary minus operator shall not be applied to an expression FC+E
whose underlying type is unsigned.
5.3.4 Evaluation of the operand to the sizeof operator shall not contain FC
side effects.
5.8.1 The right hand operand of a shift operator shall lie between zero PC
and one less than the width in bits of the underlying type of the
left hand operand.
5.14.1 The right hand operand of a logical && or || operator shall not FC
contain side effects.
Statements Support
12 QA Systems GmbH
Chapter 2: MISRA C++:2008
Statements Support
. . . continued
6.2.3 Before preprocessing, a null statement shall only occur on a line FC+E
by itself; it may be followed by a comment, provided that the first
character following the null statement is a white-space character.
6.3.1 The statement forming the body of a switch, while, do ... while or FC+E
for statement shall be a compound statement.
6.4.2 All if ... else if constructs shall be terminated with an else clause. FC+E
6.4.4 A switch-label shall only be used when the most closely-enclosing FC+E
compound statement is the body of a switch statement.
6.4.6 The final clause of a switch statement shall be the default-clause. FC+E
6.4.7 The condition of a switch statement shall not have bool type. FC+E
6.4.8 Every switch statement shall have at least one case-clause. FC+E
6.5.1 A for loop shall contain a single loop-counter which shall not have PC
floating type.
6.5.4 The loop-counter shall be modified by one of: --, ++, -=n, or +=n; PC
where n remains constant for the duration of the loop.
Statements Support
. . . continued
6.6.1 Any label referenced by a goto statement shall be declared in the FC+E
same block, or in a block enclosing the goto statement.
6.6.2 The goto statement shall jump to a label declared later in the FC+E
same function body.
6.6.4 For any iteration statement there shall be no more than one break FC+E
or goto statement used for loop termination.
6.6.5 A function shall have a single point of exit at the end of the func- FC+E
tion.
Declarations Support
7.2.1 An expression with enum underlying type shall only have values NC
corresponding to the enumerators of the enumeration.
7.3.1 The global namespace shall only contain main, namespace decla- FC+E
rations and extern "C" declarations.
7.3.2 The identifier main shall not be used for a function other than FC+E
the global function main.
14 QA Systems GmbH
Chapter 2: MISRA C++:2008
Declarations Support
. . . continued
Declarators Support
8.4.1 Functions shall not be defined using the ellipsis notation. FC+E
8.4.3 All exit paths from a function with non-void return type shall FC+E
have an explicit return statement with an expression.
8.4.4 A function identifier shall either be used to call the function or it FC+E
shall be preceded by &.
8.5.1 All variables shall have a defined value before they are used. PC
8.5.2 Braces shall be used to indicate and match the structure in the FC+E
non-zero initialization of arrays and structures.
8.5.3 In an enumerator list, the = construct shall not be used to explic- FC+E
itly initialize members other than the first, unless all items are
explicitly initialized.
Classes Support
Violations of this rule are not reported for templates as all possible
instantiations need to be known to decide whether a function can be
made const.
9.6.4 Named bit-fields with signed integer type shall have a length of FC+E
more than one bit.
10.1.2 A base class shall only be declared virtual if it is used in a diamond FC+E
hierarchy.
10.1.3 An accessible base class shall not be both virtual and non-virtual FC+E
in the same hierarchy.
10.3.1 There shall be no more than one definition of each virtual func- FC+E
tion on each path through the inheritance hierarchy.
10.3.2 Each overriding virtual function shall be declared with the virtual FC+E
keyword.
16 QA Systems GmbH
Chapter 2: MISRA C++:2008
12.1.1 An object’s dynamic type shall not be used from the body of its PC
constructor or destructor.
12.1.2 All constructors of a class should explicitly call a constructor for FC+E
all of its immediate base classes and all virtual base classes.
12.1.3 All constructors that are callable with a single argument of fun- FC+E
damental type shall be declared explicit.
12.8.1 A copy constructor shall only initialize its base classes and the FC+E
non-static members of the class of which it is a member.
Templates Support
14.6.1 In a class template with a dependent base, any name that may NC
be found in that dependent base shall be referred to using a
qualified-id or this->
Templates Support
. . . continued
14.7.3 All partial and explicit specializations for a template shall be FC+E
declared in the same file as the declaration of their primary tem-
plate.
14.8.2 The viable function set for a function call should either contain no NC
function specializations, or only contain function specializations.
15.0.3 Control shall not be transferred into a try or catch block using a FC+E
goto or a switch statement.
15.1.3 An empty throw (throw;) shall only be used in the compound- FC+E
statement of a catch handler.
15.3.1 Exceptions shall be raised only after start-up and before termina- NC
tion of the program.
15.3.2 There should be at least one exception handler to catch all other- FC+E
wise unhandled exceptions.
15.3.4 Each exception explicitly thrown in the code shall have a handler NC
of a compatible type in all call paths that could lead to that point.
15.3.6 Where multiple handlers are provided in a single try-catch state- FC+E
ment or function-try-block for a derived class and some or all
of its bases, the handlers shall be ordered most-derived to base
class.
18 QA Systems GmbH
Chapter 2: MISRA C++:2008
. . . continued
15.3.7 Where multiple handlers are provided in a single try-catch state- FC+E
ment or function-try-block, any ellipsis (catch-all) handler shall
occur last.
16.0.1 #include directives in a file shall only be preceded by other pre- FC+E
processor directives or comments.
16.0.2 Macros shall only be #define’d or #undef’d in the global names- FC+E
pace.
16.0.5 Arguments to a function-like macro shall not contain tokens that FC+E
look like preprocessing directives.
16.0.7 Undefined macro identifiers shall not be used in #if or #elif pre- FC+E
processor directives, except as operands to the defined operator.
16.0.8 If the # token appears as the first token on a line, then it shall be FC+E
immediately followed by a preprocessing token.
. . . continued
16.1.2 All #else, #elif and #endif preprocessor directives shall reside FC+E
in the same file as the #if or #ifdef directive to which they are
related.
16.2.1 The pre-processor shall only be used for file inclusion and include PC
guards.
16.2.2 C++ macros shall only be used for: include guards, type qualifiers, PC
or storage class specifiers.
16.2.4 The ’, ", /* or // characters shall not occur in a header file name. FC+E
16.2.5 The \ character should not occur in a header file name. FC+E
17.0.2 The names of standard library macros and objects shall not be PC
reused.
17.0.5 The setjmp macro and the longjmp function shall not be used. FC+E
20 QA Systems GmbH
Chapter 2: MISRA C++:2008
. . . continued
18.0.2 The library functions atof, atoi and atol from library <cstdlib> FC+E
shall not be used.
18.0.3 The library functions abort, exit, getenv and system from library FC+E
<cstdlib> shall not be used.
18.0.4 The time handling functions of library <ctime> shall not be used. FC+E
18.0.5 The unbounded functions of library <cstring> shall not be used. FC+E
18.7.1 The signal handling facilities of <csignal> shall not be used. FC+E
27.0.1 The stream input/output library <cstdio> shall not be used. FC+E
Coding guideline checks can be executed with or without runtime error analysis. Coupling QA-MISRA
with Astrée’s runtime error analysis can raise the degree to which a coding guideline is supported.
The following table shows the degree of rule support for each rule assuming no coupling. Detailed
information on the degree of support when coupled with Astrée can be found in the dedicated a3 for
C/C++ Compliance documentation.
In total, 292 rules of the rule set – i. e. 73% of all 397 rules – are checked:
Violations of this rule are reported for code that cannot be reached by
the analyzer. Such code is definitely unreachable except if the analysis
terminated prematurely because of an error. It cannot be guaranteed
that all unreachable code is reported.
0.1.2A The value returned by a function having a non-void return type FC+E
that is not an overloaded operator shall be used.
22 QA Systems GmbH
Chapter 3: AUTOSAR C++14
. . . continued
0.1.4M A project shall not contain non-volatile POD variables having only FC+E
one use.
0.1.5A There shall be no unused named parameters in the set of param- FC+E
eters for a virtual function and all the functions that override
it.
0.1.8M All functions with void return type shall have external side ef- NC
fect(s).
This rule applies to the used compiler and cannot be checked at the
source code level.
0.4.4A Range, domain and pole errors shall be checked when using math PC
functions.
General Support
This rule applies to the used compiler and cannot be checked at the
source code level.
The frontend rejects in large part violations of ISO/IEC 14882 and warns
about the use of deprecated features.
This rule applies to the used compiler and cannot be checked at the
source code level.
This rule applies to the used compiler and cannot be checked at the
source code level.
This rule applies to the used compiler and cannot be checked at the
source code level.
1.4.1A Code metrics and their valid boundaries shall be defined and S
code shall comply with defined boundaries of code metrics.
The tool supports the computation of various code metrics and provides
configurable threshold checks.
2.3.1A Only those characters specified in the C++ Language Standard FC+E
basic source character set shall be used in the source code.
24 QA Systems GmbH
Chapter 3: AUTOSAR C++14
. . . continued
2.7.1A The character \ shall not occur as a last character of a C++ com- FC+E
ment.
2.7.1M The character sequence /* shall not be used within a C-style com- FC+E
ment.
2.7.5A Comments shall not document any actions or sources (e.g. tables, NC
figures, paragraphs, etc.) that are outside of the file.
2.8.1A A header file name should reflect the logical entity for which it NC
provides declarations.
2.8.2A An implementation file name should reflect the logical entity for NC
which it provides definitions.
2.13.1A Only those escape sequences that are defined in ISO/IEC FC+E
14882:2014 shall be used.
2.13.2A String literals with different encoding prefixes shall not be con- FC+E
catenated.
2.13.2M Octal constants (other than zero) and octal escape sequences FC+E
(other than "\0") shall not be used.
. . . continued
2.13.6A Universal character names shall be used only inside character or FC+E
string literals.
3.1.2A Header files, that are defined locally in the project, shall have a FC+E
file name extension of one of: ".h", ".hpp" or ".hxx".
3.1.3A Implementation files, that are defined locally in the project, FC+E
should have a file name extension of ".cpp".
3.1.4A When an array with external linkage is declared, its size shall be PC
stated explicitly.
3.2.3M A type, object or function that is used in multiple translation units FC+E
shall be declared in one and only one file.
3.2.4M An identifier with external linkage shall have exactly one defini- PC
tion.
26 QA Systems GmbH
Chapter 3: AUTOSAR C++14
. . . continued
3.3.2M If a function has internal linkage then all re-declarations shall FC+E
include the static storage class specifier.
3.9.1A Fixed width integer types from <cstdint>, indicating the size and PC
signedness, shall be used in place of the basic numerical types.
Only use of typedefs is checked, not whether their names indicate size
and signedness. This rule check is supported by Astrée’s semantic anal-
ysis: Astrée reports overflows resulting from incorrect assumptions
about the size/signedness of numerical types.
3.9.1M The types used for an object, a function return type, or a function PC
parameter shall be token-for-token identical in all declarations
and re-declarations.
4.5.1A Expressions with type enum or enum class shall not be used as FC+E
operands to built-in and overloaded operators other than the
subscript operator [ ], the assignment operator =, the equality
operators == and ! =, the unary & operator, and the relational
operators <, <=, >, >=.
4.5.1M Expressions with type bool shall not be used as operands to built- FC+E
in operators other than the assignment operator =, the logical
operators &&, ||, !, the equality operators == and !=, the unary &
operator, and the conditional operator.
4.5.3M Expressions with type (plain) char and wchar_t shall not be used FC+E
as operands to built-in operators other than the assignment oper-
ator =, the equality operators == and !=, and the unary & operator.
. . . continued
4.10.2M Literal zero (0) shall not be used as the null-pointer-constant. FC+E
Expressions Support
5.0.1A The value of an expression shall be the same under any order of PC
evaluation that the standard permits.
5.0.3A The declaration of objects shall contain no more than two levels FC+E
of pointer indirection.
5.0.4A Pointer arithmetic shall not be used with pointers to non-final FC+E
classes.
5.0.4M An implicit integral conversion shall not change the signedness FC+E
of the underlying type.
5.0.9M An explicit integral conversion shall not change the signedness FC+E
of the underlying type of a cvalue expression.
28 QA Systems GmbH
Chapter 3: AUTOSAR C++14
Expressions Support
. . . continued
5.0.10M If the bitwise operators ~ and << are applied to an operand with FC+E
an underlying type of unsigned char or unsigned short, the result
shall be immediately cast to the underlying type of the operand.
5.0.11M The plain char type shall only be used for the storage and use of FC+E
character values.
5.0.12M signed char and unsigned char type shall only be used for the FC+E
storage and use of numeric values.
5.0.14M The first operand of a conditional-operator shall have type bool. FC+E
5.0.16M A pointer operand and any pointer resulting from pointer arith- NC
metic using that operand shall both address elements of the same
array.
5.0.18M >, >=, <, <= shall not be applied to objects of pointer type, except NC
where they point to the same array.
5.1.1A Literal values shall not be used apart from type initialization, FC
otherwise symbolic names shall be used instead.
5.1.3A Parameter list (possibly empty) shall be included in every lambda FC+E
expression.
5.1.4A A lambda expression object shall not outlive any of its reference- NC
captured objects.
5.1.6A Return type of a non-void return type lambda expression should FC+E
be explicitly specified.
5.1.8A Lambda expressions should not be defined inside another lambda FC+E
expression.
Expressions Support
. . . continued
5.2.2M A pointer to a virtual base class shall only be cast to a pointer to FC+E
a derived class by means of dynamic_cast.
5.2.3A A cast shall not remove any const or volatile qualification from FC+E
the type of a pointer or reference.
5.2.3M Casts from a base class to a derived class should not be performed FC+E
on polymorphic types.
5.2.6M A cast shall not convert a pointer to a function to any other pointer FC+E
type, including a pointer to function type.
5.2.8M An object with integer type or pointer to void type shall not be FC+E
converted to an object with pointer type.
5.2.9M A cast should not convert a pointer type to an integral type. FC+E
5.2.10M The increment (++) and decrement (--) operators should not be FC+E
mixed with other operators in an expression.
5.2.11M The comma operator, && operator and the || operator shall not FC+E
be overloaded.
5.2.12M An identifier with array type passed as a function argument shall FC+E
not decay to a pointer.
5.3.1A Evaluation of the operand to the typeid operator shall not contain FC+E
side effects.
5.3.1M Each operand of the ! operator, the logical && or the logical || FC+E
operators shall have type bool.
5.3.2M The unary minus operator shall not be applied to an expression FC+E
whose underlying type is unsigned.
30 QA Systems GmbH
Chapter 3: AUTOSAR C++14
Expressions Support
. . . continued
5.3.4M Evaluation of the operand to the sizeof operator shall not contain FC
side effects.
5.8.1M The right hand operand of a shift operator shall lie between zero PC
and one less than the width in bits of the underlying type of the
left hand operand.
5.14.1M The right hand operand of a logical && or || operator shall not FC
contain side effects.
5.16.1A The ternary conditional operator shall not be used as a sub- FC+E
expression.
Statements Support
6.2.1A Move and copy assignment operators shall either move or respec- NC
tively copy base classes and data members of a class, without any
side effects.
Statements Support
. . . continued
6.2.3M Before preprocessing, a null statement shall only occur on a line FC+E
by itself; it may be followed by a comment, provided that the first
character following the null statement is a white-space character.
6.3.1M The statement forming the body of a switch, while, do ... while or FC+E
for statement shall be a compound statement.
6.4.1A A switch statement shall have at least two case-clauses, distinct FC+E
from the default label.
6.4.2M All if ... else if constructs shall be terminated with an else clause. FC+E
6.4.4M A switch-label shall only be used when the most closely-enclosing FC+E
compound statement is the body of a switch statement.
6.4.6M The final clause of a switch statement shall be the default-clause. FC+E
6.4.7M The condition of a switch statement shall not have bool type. FC+E
6.5.1A A for-loop that loops through all elements of the container and NC
does not use its loop-counter shall not be used.
6.5.2A A for loop shall contain a single loop-counter which shall not have PC
floating-point type.
6.5.4M The loop-counter shall be modified by one of: --, ++, -=n, or +=n; PC
where n remains constant for the duration of the loop.
32 QA Systems GmbH
Chapter 3: AUTOSAR C++14
Statements Support
. . . continued
6.6.1M Any label referenced by a goto statement shall be declared in the FC+E
same block, or in a block enclosing the goto statement.
6.6.2M The goto statement shall jump to a label declared later in the FC+E
same function body.
Declaration Support
7.1.2A The constexpr specifier shall be used for values that can be deter- NC
mined at compile time.
7.1.3A CV-qualifiers shall be placed on the right hand side of the type NC
that is a typedef or a using name.
7.1.5A The auto specifier shall not be used apart from following cases: FC
(1) to declare that a variable has the same type as return type of
a function call, (2) to declare that a variable has the same type as
initializer of non-fundamental type, (3) to declare parameters of
a generic lambda expression, (4) to declare a function template
using trailing return type syntax.
Declaration Support
. . . continued
7.2.1A An expression with enum underlying type shall only have values PC
corresponding to the enumerators of the enumeration.
7.2.4A In an enumeration, either (1) none, (2) the first or (3) all enumer- FC+E
ators shall be initialized.
7.3.1M The global namespace shall only contain main, namespace decla- FC+E
rations and extern "C" declarations.
7.3.2M The identifier main shall not be used for a function other than FC+E
the global function main.
34 QA Systems GmbH
Chapter 3: AUTOSAR C++14
Declaration Support
. . . continued
7.6.1A Functions declared with the [[noreturn]] attribute shall not re- FC
turn.
Declarators Support
8.2.1A When declaring function templates, the trailing return type syn- FC
tax shall be used if the return type depends on the type of param-
eters.
8.4.1A Functions shall not be defined using the ellipsis notation. FC+E
8.4.2A All exit paths from a function with non-void return type shall FC+E
have an explicit return statement with an expression.
8.4.4M A function identifier shall either be used to call the function or it FC+E
shall be preceded by &.
Declarators Support
. . . continued
8.4.7A "in" parameters for "cheap to copy" types shall be passed by value. FC+E
8.5.2M Braces shall be used to indicate and match the structure in the FC+E
non-zero initialization of arrays and structures.
8.5.3A A variable of type auto shall not be initialized using {} or ={} FC+E
braced-initialization.
36 QA Systems GmbH
Chapter 3: AUTOSAR C++14
Classes Support
Violations of this rule are not reported for templates as all possible
instantiations need to be known to decide whether a function can be
made const.
The exception for "tagged unions" is not taken into account. It is sug-
gested to encapsulate and annotate unions which shall be excluded
from this check.
9.6.4M Named bit-fields with signed integer type shall have a length of FC+E
more than one bit.
10.1.1A Class shall not be derived from more than one base class which FC+E
is not an interface class.
. . . continued
10.1.2M A base class shall only be declared virtual if it is used in a diamond FC+E
hierarchy.
10.1.3M An accessible base class shall not be both virtual and non-virtual FC+E
in the same hierarchy.
10.3.1A Virtual function declaration shall contain exactly one of the three FC+E
specifiers: (1) virtual, (2) override, (3) final.
10.3.2A Each overriding virtual function shall be declared with the over- FC+E
ride or final specifier.
11.0.2A A type defined as struct shall: (1) provide only public data mem- FC+E
bers, (2) not provide any special member functions or methods,
(3) not be a base of another struct or class, (4) not inherit from
another struct or class.
38 QA Systems GmbH
Chapter 3: AUTOSAR C++14
12.1.1A Constructors shall explicitly initialize all virtual base classes, all FC+E
direct non-virtual base classes and all non-static data members.
12.1.1M An object’s dynamic type shall not be used from the body of its PC
constructor or destructor.
12.1.4A All constructors that are callable with a single argument of fun- FC+E
damental type shall be declared explicit.
12.4.1A Destructor of a base class shall be public virtual, public override FC+E
or protected non-virtual.
12.4.2A If a public destructor of a class is non-virtual, then the class should FC+E
be declared final.
12.6.1A All class data members that are initialized by the constructor PC
shall be initialized using member initializers.
12.8.1A Move and copy constructors shall move and respectively copy NC
base classes and data members of a class, without any side effects.
. . . continued
12.8.4A Move constructor shall not initialize its class members and base FC+E
classes using copy semantics.
12.8.6A Copy and move constructors and copy assignment and move FC+E
assignment operators shall be declared protected or defined
"=delete" in base class.
Overloading Support
13.1.2A User defined suffixes of the user defined literal operators shall FC+E
start with underscore followed by one or more letters.
13.2.2A A binary arithmetic operator and a bitwise operator shall return FC+E
a "prvalue".
40 QA Systems GmbH
Chapter 3: AUTOSAR C++14
Overloading Support
. . . continued
13.6.1A Digit sequences separators ’ shall only be used as follows: (1) for FC+E
decimal, every 3 digits, (2) for hexadecimal, every 2 digits, (3) for
binary, every 4 digits.
Templates Support
14.5.2A Class members that are not dependent on template class parame- PC
ters should be defined in a separate base class.
14.6.1M In a class template with a dependent base, any name that may NC
be found in that dependent base shall be referred to using a
qualified-id or this->
14.7.2A Template specialization shall be declared in the same file (1) as FC+E
the primary template (2) as a user-defined type, for which the
specialization is declared.
. . . continued
15.0.2A At least the basic guarantee for exception safety shall be provided NC
for all operations. In addition, each function may offer either the
strong guarantee or the nothrow guarantee
15.0.3M Control shall not be transferred into a try or catch block using a FC+E
goto or a switch statement.
15.1.3M An empty throw (throw;) shall only be used in the compound- FC+E
statement of a catch handler.
15.1.4A If a function exits with an exception, then before a throw, the func- NC
tion shall place all objects/resources that the function constructed
in valid states or it shall delete them.
42 QA Systems GmbH
Chapter 3: AUTOSAR C++14
. . . continued
15.2.1A Constructors that are not noexcept shall not be invoked before FC+E
program startup.
15.3.1M Exceptions shall be raised only after start-up and before termina- NC
tion of the program.
15.3.3A Main function and a task main function shall catch at least: base PC
class exceptions from all third-party libraries used, std::exception
and all otherwise unhandled exceptions.
15.3.4M Each exception explicitly thrown in the code shall have a handler NC
of a compatible type in all call paths that could lead to that point.
15.3.5A A class type exception shall be caught by reference or const refer- FC+E
ence.
15.3.6M Where multiple handlers are provided in a single try-catch state- FC+E
ment or function-try-block for a derived class and some or all
of its bases, the handlers shall be ordered most-derived to base
class.
15.3.7M Where multiple handlers are provided in a single try-catch state- FC+E
ment or function-try-block, any ellipsis (catch-all) handler shall
occur last.
. . . continued
16.0.1A The pre-processor shall only be used for unconditional and condi- PC
tional file inclusion and include guards, and using the following
directives: (1) #ifndef, (2) #ifdef, (3) #if, (4) #if defined, (5) #elif,
(6) #else, (7) #define, (8) #endif, (9) #include.
16.0.1M #include directives in a file shall only be preceded by other pre- FC+E
processor directives or comments.
16.0.2M Macros shall only be #define’d or #undef’d in the global names- FC+E
pace.
16.0.5M Arguments to a function-like macro shall not contain tokens that FC+E
look like preprocessing directives.
44 QA Systems GmbH
Chapter 3: AUTOSAR C++14
. . . continued
16.0.7M Undefined macro identifiers shall not be used in #if or #elif pre- FC+E
processor directives, except as operands to the defined operator.
16.0.8M If the # token appears as the first token on a line, then it shall be FC+E
immediately followed by a preprocessing token.
16.1.2M All #else, #elif and #endif preprocessor directives shall reside FC+E
in the same file as the #if or #ifdef directive to which they are
related.
16.2.1A The ’, ", /*, //, \ characters shall not occur in a header file name or FC+E
in #include directive.
Library and any third-party user code can be checked for compliance
by either adding it to the checked project or analyzing it separately.
17.0.2M The names of standard library macros and objects shall not be PC
reused.
. . . continued
17.0.5M The setjmp macro and the longjmp function shall not be used. FC+E
18.0.1A The C library facilities shall only be accessed through C++ library FC+E
headers.
18.0.3A The library <clocale> (locale.h) and the setlocale function shall PC
not be used.
18.0.3M The library functions abort, exit, getenv and system from library FC+E
<cstdlib> shall not be used.
18.0.4M The time handling functions of library <ctime> shall not be used. FC+E
18.0.5M The unbounded functions of library <cstring> shall not be used. FC+E
18.1.6A All std::hash specializations for user-defined types shall have a FC+E
noexcept function call operator.
18.5.1A Functions malloc, calloc, realloc and free shall not be used. FC+E
18.5.3A The form of the delete expression shall match the form of the NC
new expression used to allocate the memory.
46 QA Systems GmbH
Chapter 3: AUTOSAR C++14
. . . continued
18.5.8A Objects that do not outlive a function shall have automatic storage NC
duration.
18.5.10A Placement new shall be used only with properly aligned pointers PC
to sufficient storage capacity.
18.7.1M The signal handling facilities of <csignal> shall not be used. FC+E
18.9.2A Forwarding values to other functions shall be done via: (1) FC+E
std::move if the value is an rvalue reference, (2) std::forward
if the value is forwarding reference.
18.9.3A The std::move shall not be used on objects declared const or FC+E
const&.
48 QA Systems GmbH
Chapter 3: AUTOSAR C++14
27.0.1M The stream input/output library <cstdio> shall not be used. FC+E
27.0.2A A C-style string shall guarantee sufficient space for data and the NC
null terminator.
27.0.3A Alternate input and output operations on a file stream shall not NC
be used without an intervening flush or positioning call.
[1] AUTOSAR. Guidelines for the use of the C++14 language in critical and safety-related systems (release
19-03), Mar 2019.
50 QA Systems GmbH