C and C++


LANG.STRUCT.GLABEL : Label Not In Enclosing Block

Summary

A goto statement refers to a label that is not in the block that (transitively) contains the goto statement.

This class is a strict subset of Goto Statement.

Properties

Class Name Label Not In Enclosing Block
Significance style
Mnemonic LANG.STRUCT.GLABEL
Categories
MisraC2023 MisraC2023:15.3 Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement
Misra2012 Misra2012:15.3 Any label referenced by a goto statement shall be declared in the same block, or in any block enclosing the goto statement
Misra2004 Misra2004:14.4 The goto statement shall not be used
AUTOSARC++14 AUTOSARC++14:M6-6-1 Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement.
MisraC++2008 MisraC++2008:6-6-1 Any label referenced by a goto statement shall be declared in the same block, or in a block enclosing the goto statement.
MisraC++2023 MisraC++2023:9.6.2 A goto statement shall reference a label in a surrounding block
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="Label Not In Enclosing Block"
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

int lang_struct_glabel(int i){
    int a = 1;
    if (i < 10) { 
        goto lA;   /* 'Label Not in Enclosing Block' warning issued here. */
    }
    if (i < 20){
        lA: a= 5;
    }
    return a;
}

Relevant Configuration File Parameters

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