Main Content

AUTOSAR C++14 Rule A2-13-6

Universal character names shall be used only inside character or string literals

Since R2020a

Description

Rule Definition

Universal character names shall be used only inside character or string literals.

Rationale

Universal character names are a way to represent unicode characters by using code points. For example, \U0000231A represents the unicode character '⌚'. When you use universal character names to define an identifier, it is difficult to read the source code. Using universal character names as identifier is confusing and troublesome. Avoid using universal character names outside a character or string literal.

Polyspace Implementation

Polyspace® flags the use of universal character names outside a character or string literal.

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

The following example demonstrate the Polyspace implementation of AUTOSAR rule A2-13-6.

#include <cstdint>
#define \U0000231AMACRO(x) (x)     // Noncompliant
void €uro(){            // Compliant 
	std::int32_t €uro;    // Compliant
	std::int32_t \U0000231Ahello; // Noncompliant
	wchar_t wc = '\U0000231A';    // Compliant
	std::int32_t Hello\U0000231AWorld;  // Noncompliant
}
typedef struct \U0000231Astruct {    // Noncompliant
	std::int32_t regular; 
	std::int32_t €uro;                // Compliant 
	std::int32_t \U0000231Ahello;     // Noncompliant
} \U0001f615type;                // Noncompliant

main(){
	//...
}

The variable \U0000231Ahello is declared using universal character name. Such a variable name is difficult to use, and makes the code confusing. Polyspace flags the use of universal character names outside a character or string literal.

Check Information

Group: Lexical conventions
Category: Required, Automated

Version History

Introduced in R2020a