CertC++-PRE30ΒΆ

Do not create a universal character name through concatenation

Required inputs: IR

The C Standard supports universal character names that may be used in identifiers, character constants, and string literals to designate characters that are not in the basic character set. The universal character name \Unnnnnnnn designates the character whose 8-digit short identifier (as specified by ISO/IEC 10646) is nnnnnnnn. Similarly, the universal character name \unnnn designates the character whose 4-digit short identifier is nnnn (and whose 8-digit short identifier is 0000nnnn).

The C Standard, 5.1.1.2, paragraph 4 [ ISO/IEC 9899:2011], says

If a character sequence that matches the syntax of a universal character name is produced by token concatenation (6.10.3.3), the behavior is undefined.

See also undefined behavior 3.

In general, avoid universal character names in identifiers unless absolutely necessary.

Noncompliant Code Example

This code example is noncompliant because it produces a universal character name by token concatenation:

#define assign(uc1, uc2, val) uc1##uc2 = val

void func(void) {
  int \u0401;
  /* ... */
  assign(\u04, 01, 4);
  /* ... */
}
Implementation Details

This code compiles and runs with Microsoft Visual Studio 2013, assigning 4 to the variable as expected.

GCC 4.8.1 on Linux refuses to compile this code; it emits a diagnostic reading, "stray '\' in program," referring to the universal character fragment in the invocation of the assign macro.

Compliant Solution

This compliant solution uses a universal character name but does not create it by using token concatenation:

#define assign(ucn, val) ucn = val
 
void func(void) {
  int \u0401;
  /* ... */
  assign(\u0401, 4);
  /* ... */
}
Risk Assessment

Creating a universal character name through token concatenation results in undefined behavior.

Rule Severity Likelihood Remediation Cost Priority Level
PRE30-C Low Unlikely Medium P2 L3
Bibliography
[ ISO/IEC 10646-2003]
[ ISO/IEC 9899:2011] Subclause 5.1.1.2, "Translation Phases"
Excerpt from SEI CERT C++ Coding Standard [https://cmu-sei.github.io/secure-coding-standards/sei-cert-c-coding-standard/rules/preprocessor-pre/pre30-c], Copyright (C) 1995-2026 Carnegie Mellon University. See section 9.4. "3rd-Party Licenses" in the documentation for full details.

Possible Messages

Key

Text

Severity

Disabled

universal_name_by_concat

Do not create a universal character name through concatenation

None

False

Options