JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.TYPE.MDS : Misplaced Digit Separator

Summary

A numeric literal contains one or more digit separators ('), but the separator usage does not conform to the following policy.

decimal, octal separator every 3 digits
hexadecimal separator every 2 digits
binary separator every 4 digits

A numeric literal with no digit separators will not trigger a warning of this class.

Digit separators were introduced in C++14 and C23. If you are using an earlier version, digit separators may cause a compiler error.

Properties

Class Name Misplaced Digit Separator
Significance style
Mnemonic LANG.TYPE.MDS
Categories
AUTOSARC++14 AUTOSARC++14:A13-6-1 Digit sequences separators ' shall only be used as follows: (1) for decimal, every 3 digits, (2) for hexadecimal, every 2 digits, (3) for binary, every 4 digits.
CWE CWE:1076 Insufficient Adherence to Expected Conventions
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Misplaced Digit Separator"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

// Decimals and octals: every three digits (or none)
int jenny = 867'5309;          // 'Misplaced Digit Separator' warning issued here
int taxi = 1'729;                                    // ok
int alldigits = 1234567'890;   // 'Misplaced Digit Separator' warning issued here
float pi_approx = 3.141'15;                          // ok
double e_approx = 2.7182818;                         // ok
int all = 0777;                                      // ok

// Hexadecimals:  every two digits (or none)
int mask = 0xff'ff;                                  // ok
int mask_nosep = 0xffff;                             // ok
int mask_badsep = 0xf'fff;     // 'Misplaced Digit Separator' warning issued here

// Binary numbers: every four digits (or none)
int sig = 0b1101'1111;                               // ok
int sig_nosep = 0b11011111;                          // ok
int sig_badsep = 0b11'011'111; // 'Misplaced Digit Separator' warning issued here

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.