AutosarC++18_03-A2.13.1

Only those escape sequences that are defined in ISO/IEC 14882:2014 shall be used

Required inputs: IR

Rationale

The use of an undefined escape sequence leads to undefined behavior. The defined escape sequences (ISO/IEC 14882:2014) are: \’, \", \?, \\, \a, \b, \f, \n, \r, \t, \v, \<Octal Number>, \x<Hexadecimal Number>.

Note: Universal-character-names (\u hex-quad and \U hex-quad hex-quad) are also allowed in character and string literals (although they look similar to escape sequences, they are handled in a different way by the C++ language, see A2-13-6).

Example
//% $Id: A2-13-1.cpp 305629 2018-01-29 13:29:25Z piotr.serwa $
#include <string>
void F() {
  const std::string a = "\k";         // Non-compliant
  const std::string b = "\n";         // Compliant
  const std::string c = "\U0001f34c"; // Compliant
}
See Also
  • MISRA C++ 2008 [6]: required 2-13-1 Only those escape sequences that are defined in ISO/IEC14882:2003 shall be used.

Possible Messages

Key

Text

Severity

Disabled

nonstandard_escape_sequence

Use of non-standard escape sequence.

None

False

Options

allow_delimited_escape_sequences

allow_delimited_escape_sequences : bool = False

Whether to allow C++23 escape sequences that are delimited by curly braces. This includes the delimited escape sequences `\u{}`, `\x{}`, and `\o{}` as well as named universal character escapes of the form `\N{}`.
 

allowed

allowed : str = ''"?\abfnrtv'

List of allowed characters after backslash.