Main Content

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.

Polyspace Implementation

The rule checker reports violations on use of escape sequences outside those that are defined in the ISO/IEC 14882:2003 Standard.

Troubleshooting

If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.

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

Version History

Introduced in R2013b