Next: , Previous: Style-Related Rules   [Contents][Index]

2 Feature Usage Rules

The rules in this chapter can be used to enforce specific usage patterns for a variety of language features.


Next: , Up: Feature Usage Rules   [Contents][Index]

2.1 Abstract_Type_Declarations

Flag all declarations of abstract types. For an abstract private type, both the private and full type declarations are flagged.

This rule has no parameters.


Next: , Previous: Abstract_Type_Declarations, Up: Feature Usage Rules   [Contents][Index]

2.2 Anonymous_Subtypes

Flag all uses of anonymous subtypes (except cases when subtype indication is a part of a record component definition, and this subtype indication depends on a discriminant). A use of an anonymous subtype is any instance of a subtype indication with a constraint, other than one that occurs immediately within a subtype declaration. Any use of a range other than as a constraint used immediately within a subtype declaration is considered as an anonymous subtype.

An effect of this rule is that for loops such as the following are flagged (since 1..N is formally a “range”):

for I in 1 .. N loop
   …
end loop;

Declaring an explicit subtype solves the problem:

subtype S is Integer range 1..N;
…
for I in S loop
   …
end loop;

This rule has no parameters.


Next: , Previous: Anonymous_Subtypes, Up: Feature Usage Rules   [Contents][Index]

2.3 Blocks

Flag each block statement.

This rule has no parameters.


Next: , Previous: Blocks, Up: Feature Usage Rules   [Contents][Index]

2.4 Complex_Inlined_Subprograms

Flags a subprogram (or generic subprogram) if pragma Inline is applied to the subprogram and at least one of the following conditions is met:

This rule has the following (mandatory) parameter for the +R option:

N

Positive integer specifying the maximum allowed total number of statements in the subprogram body.


Next: , Previous: Complex_Inlined_Subprograms, Up: Feature Usage Rules   [Contents][Index]

2.5 Controlled_Type_Declarations

Flag all declarations of controlled types. A declaration of a private type is flagged if its full declaration declares a controlled type. A declaration of a derived type is flagged if its ancestor type is controlled. Subtype declarations are not checked. A declaration of a type that itself is not a descendant of a type declared in Ada.Finalization but has a controlled component is not checked.

This rule has no parameters.


Next: , Previous: Controlled_Type_Declarations, Up: Feature Usage Rules   [Contents][Index]

2.6 Declarations_In_Blocks

Flag all block statements containing local declarations. A declare block with an empty declarative_part or with a declarative part containing only pragmas and/or use clauses is not flagged.

This rule has no parameters.


Next: , Previous: Declarations_In_Blocks, Up: Feature Usage Rules   [Contents][Index]

2.7 Deeply_Nested_Inlining

Flags a subprogram (or generic subprogram) if pragma Inline has been applied to the subprogram but the subprogram calls to another inlined subprogram that results in nested inlining with nesting depth exceeding the value specified by the N rule parameter.

This rule requires the global analysis of all the compilation units that are gnatcheck arguments; such analysis may affect the tool’s performance.

This rule has the following (mandatory) parameter for the +R option:

N

Positive integer specifying the maximal allowed level of nested inlining.


Next: , Previous: Deeply_Nested_Inlining, Up: Feature Usage Rules   [Contents][Index]

2.8 Default_Parameters

Flag all default expressions in parameters specifications. All parameter specifications are checked: in subprograms (including formal, generic and protected subprograms) and in task and protected entries (including accept statements and entry bodies).

This rule has no parameters.


Next: , Previous: Default_Parameters, Up: Feature Usage Rules   [Contents][Index]

2.9 Discriminated_Records

Flag all declarations of record types with discriminants. Only the declarations of record and record extension types are checked. Incomplete, formal, private, derived and private extension type declarations are not checked. Task and protected type declarations also are not checked.

This rule has no parameters.


Next: , Previous: Discriminated_Records, Up: Feature Usage Rules   [Contents][Index]

2.10 Explicit_Full_Discrete_Ranges

Flag each discrete range that has the form A'First .. A'Last.

This rule has no parameters.


Next: , Previous: Explicit_Full_Discrete_Ranges, Up: Feature Usage Rules   [Contents][Index]

2.11 Float_Equality_Checks

Flag all calls to the predefined equality operations for floating-point types. Both “=” and “/=” operations are checked. User-defined equality operations are not flagged, nor are “=” and “/=” operations for fixed-point types.

This rule has no parameters.


Next: , Previous: Float_Equality_Checks, Up: Feature Usage Rules   [Contents][Index]

2.12 Function_Style_Procedures

Flag each procedure that can be rewritten as a function. A procedure can be converted into a function if it has exactly one parameter of mode out and no parameters of mode in out. Procedure declarations, formal procedure declarations, and generic procedure declarations are always checked. Procedure bodies and body stubs are flagged only if they do not have corresponding separate declarations. Procedure renamings and procedure instantiations are not flagged.

If a procedure can be rewritten as a function, but its out parameter is of a limited type, it is not flagged.

Protected procedures are not flagged. Null procedures also are not flagged.

This rule has no parameters.


Next: , Previous: Function_Style_Procedures, Up: Feature Usage Rules   [Contents][Index]

2.13 Generics_In_Subprograms

Flag each declaration of a generic unit in a subprogram. Generic declarations in the bodies of generic subprograms are also flagged. A generic unit nested in another generic unit is not flagged. If a generic unit is declared in a local package that is declared in a subprogram body, the generic unit is flagged.

This rule has no parameters.


Next: , Previous: Generics_In_Subprograms, Up: Feature Usage Rules   [Contents][Index]

2.14 Implicit_IN_Mode_Parameters

Flag each occurrence of a formal parameter with an implicit in mode. Note that access parameters, although they technically behave like in parameters, are not flagged.

This rule has no parameters.


Next: , Previous: Implicit_IN_Mode_Parameters, Up: Feature Usage Rules   [Contents][Index]

2.15 Improperly_Located_Instantiations

Flag all generic instantiations in library-level package specs (including library generic packages) and in all subprogram bodies.

Instantiations in task and entry bodies are not flagged. Instantiations in the bodies of protected subprograms are flagged.

This rule has no parameters.


Next: , Previous: Improperly_Located_Instantiations, Up: Feature Usage Rules   [Contents][Index]

2.16 Library_Level_Subprograms

Flag all library-level subprograms (including generic subprogram instantiations).

This rule has no parameters.


Next: , Previous: Library_Level_Subprograms, Up: Feature Usage Rules   [Contents][Index]

2.17 Non_Qualified_Aggregates

Flag each non-qualified aggregate. A non-qualified aggregate is an aggregate that is not the expression of a qualified expression. A string literal is not considered an aggregate, but an array aggregate of a string type is considered as a normal aggregate. Aggregates of anonymous array types are not flagged.

This rule has no parameters.


Next: , Previous: Non_Qualified_Aggregates, Up: Feature Usage Rules   [Contents][Index]

2.18 Numeric_Literals

Flag each use of a numeric literal in an index expression, and in any circumstance except for the following:

This rule may have the following parameters for the +R option:

N

N is an integer literal used as the maximal value that is not flagged (i.e., integer literals not exceeding this value are allowed)

ALL

All integer literals are flagged

If no parameters are set, the maximum unflagged value is 1.

The last specified check limit (or the fact that there is no limit at all) is used when multiple +R options appear.

The -R option for this rule has no parameters. It disables the rule but retains the last specified maximum unflagged value. If the +R option subsequently appears, this value is used as the threshold for the check.


Next: , Previous: Numeric_Literals, Up: Feature Usage Rules   [Contents][Index]

2.19 Parameters_Out_Of_Order

Flag each subprogram and entry declaration whose formal parameters are not ordered according to the following scheme:

Only the first violation of the described order is flagged.

The following constructs are checked:

Subprogram renamings are not checked.

This rule has no parameters.


Next: , Previous: Parameters_Out_Of_Order, Up: Feature Usage Rules   [Contents][Index]

2.20 Raising_Predefined_Exceptions

Flag each raise statement that raises a predefined exception (i.e., one of the exceptions Constraint_Error, Numeric_Error, Program_Error, Storage_Error, or Tasking_Error).

This rule has no parameters.


Next: , Previous: Raising_Predefined_Exceptions, Up: Feature Usage Rules   [Contents][Index]

2.21 Unassigned_OUT_Parameters

Flags procedures’ out parameters that are not assigned, and identifies the contexts in which the assignments are missing.

An out parameter is flagged in the statements in the procedure body’s handled sequence of statements (before the procedure body’s exception part, if any) if this sequence of statements contains no assignments to the parameter.

An out parameter is flagged in an exception handler in the exception part of the procedure body’s handled sequence of statements if the handler contains neither assignment to the parameter nor a raise statement.

Bodies of generic procedures are also considered.

The following are treated as assignments to an out parameter:

This rule does not have any parameters.


Previous: Unassigned_OUT_Parameters, Up: Feature Usage Rules   [Contents][Index]

2.22 Unconstrained_Array_Returns

Flag each function returning an unconstrained array. Function declarations, function bodies (and body stubs) having no separate specifications, and generic function instantiations are checked. Function calls and function renamings are not checked.

Generic function declarations, and function declarations in generic packages are not checked, instead this rule checks the results of generic instantiations (that is, expanded specification and expanded body corresponding to an instantiation).

This rule has no parameters.


Previous: Unassigned_OUT_Parameters, Up: Feature Usage Rules   [Contents][Index]