MISRA C++:2008 Rule 2-13-1

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

Description

Rule Definition

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

Rationale

Escape sequences are certain special characters represented in string and character literals. They are written with a backslash (\) followed by a character.

The C++ Standard (ISO/IEC 14882:2003, Sec. 2.13.2) defines a list of escape sequences. See Escape Sequences. Use of escape sequences (backslash followed by character) outside that list leads to undefined behavior.

Additional Message in Report

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

\char is not an ISO/IEC escape sequence.

Troubleshooting

If you expect a rule violation but do not see it, refer to Coding Standard Violations Not Displayed.

Examples

expand all

void func () {
  const char a[2] = "\k"; //Noncompliant
  const char b[2] = "\b"; //Compliant
}

In this example, \k is not a recognized escape sequence.

Check Information

Group: Lexical Conventions
Category: Required
Introduced in R2013b