MISRAC2012-Rule-23.6
In this section:
Synopsis
(Required) The controlling expression of a generic selection shall have an essential type that matches its standard type.
Enabled by default
Yes
Severity/Certainty
Medium/Medium

Full description
Found generic selection not using an essential type that matches its standard type.
Coding standards
- MISRA C:2012 Rule-23.6
(Required) The controlling expression of a generic selection shall have an essential type that matches its standard type.
Code examples
The following code example fails the check and will give a warning:
void handle_short(short s);
void handle_int(int i);
#define filter_ints(X) ( _Generic((X) \
, short: handle_short \
, int : handle_int ) (X) )
void example(void) {
short s16 = 0;
/* Non-compliant */
filter_ints (s16 + s16); /* Selects int, essentially short */
}
The following code example passes the check and will not give a warning about this issue:
void handle_short(short s);
void handle_int(int i);
#define filter_ints(X) ( _Generic((X) \
, short: handle_short \
, int : handle_int ) (X) )
void example(void) {
short s16 = 0;
/* Compliant */
filter_ints (s16);
}