C and C++


LANG.TYPE.MSUF : Missing Literal Suffix

Summary

An integer constant does not have a 'U' or 'u' suffix, but is of unsigned type.

The type of a constant is determined from its value and format, and from whether the code is compiled as C90 or C99.

Properties

Class Name Missing Literal Suffix
Significance style
Mnemonic LANG.TYPE.MSUF
Categories
MisraC2023 MisraC2023:7.2 A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type
Misra2012 Misra2012:7.2 A "u" or "U" suffix shall be applied to all integer constants that are represented in an unsigned type
Misra2004 Misra2004:10.6 A "U" suffix shall be applied to all constants of unsigned type
AUTOSARC++14 AUTOSARC++14:M2-13-3 A "U" suffix shall be applied to all octal or hexadecimal integer literals of unsigned type.
MisraC++2008 MisraC++2008:2-13-3 A "U" suffix shall be applied to all octal or hexadecimal integer literals of unsigned type.
MisraC++2023 MisraC++2023:5.13.4 Unsigned integer literals shall be appropriately suffixed
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="Missing Literal Suffix"
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

Suppose the following code is compiled to a target with 32-bit integers.

unsigned int ui1 = 0xF;                          /* signed int */
unsigned int ui2 = 0xFFFFFFF;                    /* signed int */
unsigned int ui3 = 0xFFFFFFFFu;                  /* unsigned int with 'u' suffix */
unsigned int ui4 = 037777777777; /* 'Missing Literal Suffix' warning issued here */
unsigned int ui5 = 4294967295;   /* 'Missing Literal Suffix' warning issued here for C90 only (not C99) */

int fA(int i){return i;}

void fB(void){
  fA(0xF);                                       /* signed int */
  fA(0xFFFFFFFF);                /* 'Missing Literal Suffix' warning issued here */
}

Relevant Configuration File Parameters

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