Main Content

AUTOSAR C++14 Rule A2-13-3

Type wchar_t shall not be used

Description

Rule Definition

Type wchar_t shall not be used.

Rationale

The size of wchar_t is implementation-dependent. If you use wchar_t for Unicode values, your code is bound to a specific compiler.

To improve the portability of your code, use char16_t and char32_t instead. These are standard types introduced in C++11 for text strings with UTF-16 and UTF-32 encodings.

Polyspace Implementation

The rule checker flags all uses of the wchar_t keyword.

If you do not want to fix the issue, add a comment justifying the result. See:

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

char16_t str1[] = u"A UTF-16 string";  //Compliant
char32_t str2[] = U"A UTF-32 string";  //Compliant 
wchar_t str3[] = L"A Unicode string";  //Noncompliant

The use of wchar_t violates this rule. Instead the types char16_t and char32_t can be used.

Check Information

Group: Lexical conventions
Category: Required, Automated

Version History

Introduced in R2019a