MISRA C:2012 Rule 1.4

Emergent language features shall not be used

Description

Rule Definition

Emergent language features shall not be used.

Rationale

Some new language features in the C11 Standard have undefined, unspecified or implementation-defined behavior. These features might also exhibit well-defined behavior that defies developer expectations. Though rule 1.3 and directive 1.1 prohibits undefined and implementation-defined behavior, to avoid well-defined behavior that defies expectations, some language features are summarily discouraged using rule 1.4.

Polyspace Implementation

The rule forbids use of the following language features:

  • The _Generic operator.

  • The _Noreturn function specifier and the <stdnoreturn.h> header file

  • The _Atomic type specifier and the facilities provided by <stdatomic.h> (for instance, the macros beginning with ATOMIC_ and functions beginning with atomic_ implemented as macros in <stdatomic.h>).

  • The _Thread_local storage class specifier and the facilities provided by <threads.h> (for instance, types such as thrd_t and functions such as thrd_create).

  • The _Alignas alignment specifier, the _Alignof operator and the <stdalign.h> header file, and facilities therein (such as the alignas and alignof macros).

  • All facilities in Annex K of the C11 Standard about 'Bound-checking interfaces', other than defining __STDC_WANT_LIB_EXT1__ to '0'

Troubleshooting

If you expect a rule violation but do not see it, refer to the documentation of Polyspace® Code Prover™ or Polyspace Code Prover Server™.

Examples

expand all

#define __STDC_WANT_LIB_EXT1__ 1 //Noncompliant
#include <string.h>

void Copying_functions(void) {
    char buf1[10];
    char buf2[10];
    errno_t e;  //Noncompliant
    e = memcpy_s(buf1,sizeof(buf1),buf2,5); //Noncompliant
    e = memmove_s(buf1,sizeof(buf1),buf2,5); //Noncompliant
    e = strcpy_s(buf1,sizeof(buf1),buf2); //Noncompliant
    e = strncpy_s(buf1,sizeof(buf1),buf2,5); //Noncompliant
}

In this example, the macro __STDC_WANT_LIB_EXT1__ is set to 1 so that the type errno_t as defined in the header stdlib.h can be used (in accordance with Annex K of the C11 Standard).

The checker flags both the setting of the macro to 1 and the definition of the errno_t variable, along with other functions from Annex K.

Check Information

Group: Standard C Environment
Category: Required
AGC Category: Required
Introduced in R2014b