C and C++


LANG.STRUCT.DECL.MGT : Global Variable Declared with Different Types

Summary

A global variable has been declared in multiple places with different types.

Properties

Class Name Global Variable Declared with Different Types
Significance reliability
Mnemonic LANG.STRUCT.DECL.MGT
Categories
MisraC2023 MisraC2023:8.3 All declarations of an object or function shall use the same names and type qualifiers
Misra2012 Misra2012:8.3 All declarations of an object or function shall use the same names and type qualifiers
Misra2004 Misra2004:8.3 For each function parameter the type given in the declaration and definition shall be identical, and the return types shall also be identical
  Misra2004:8.4 If objects or functions are declared more than once their types shall be compatible
  Misra2004:16.4 The identifiers used in the declaration and definition of a function shall be identical
AUTOSARC++14 AUTOSARC++14:M3-2-1 All declarations of an object or function shall have compatible types.
  AUTOSARC++14:M3-9-1 The types used for an object, a function return type, or a function parameter shall be token-for-token identical in all declarations and re-declarations.
MisraC++2008 MisraC++2008:3-2-1 All declarations of an object or function shall have compatible types.
  MisraC++2008:3-9-1 The types used for an object, a function return type, or a function parameter shall be token-for-token identical in all declarations and re-declarations.
MisraC++2023 MisraC++2023:6.2.2 All declarations of a variable or function shall have the same type
CWE CWE:710 Improper Adherence to Coding Standards
TS17961 TS17961:5.13-funcdecl 5.13. Declaring the same function or object in incompatible ways
CERT-C CERT-C:DCL23-C Guarantee that mutually visible identifiers are unique
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="Global Variable Declared with Different Types"
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

A warning will be issued for the following pair of declarations.

/* LANG.STRUCT.DECL.MGT.a.c */

int params[10];
/* LANG.STRUCT.DECL.MGT.b.c */

int params[]; /* 'Global Variable Declared with Different Types' warning issued here */

Relevant Configuration File Parameters

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