Main Content

AUTOSAR C++14 Rule A2-13-1

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

Description

Rule Definition

Only those escape sequences that are defined in ISO/IEC 14882:2014 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.

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

#include <string>
void func () {
  const std::string a = "\k"; //Noncompliant
  const std::string b = "\U0001f34c"; //Compliant
}

In this example, Polyspace reports a violation on the unrecognized escape sequence \k.

Check Information

Group: Lexical Conventions
Category: Required, Automated

Version History

Introduced in R2019a

expand all