File tree Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Expand file tree Collapse file tree 3 files changed +17
-6
lines changed Original file line number Diff line number Diff line change 11/**
22 * @id c/cert/declare-identifiers-before-using-them
33 * @name DCL31-C: Declare identifiers before using them
4- * @description Omission of type specifiers may not be supported by some compilers.
4+ * @description Omission of type specifiers may not be supported by some
5+ * compilers.
56 * @kind problem
67 * @precision very-high
78 * @problem.severity error
@@ -17,5 +18,12 @@ import codingstandards.c.cert
1718from Declaration d
1819where
1920 not isExcluded ( d , Declarations1Package:: declareIdentifiersBeforeUsingThemQuery ( ) ) and
20- d .hasSpecifier ( "implicit_int" )
21+ d .hasSpecifier ( "implicit_int" ) and
22+ exists ( Type t |
23+ ( d .( Variable ) .getType ( ) = t or d .( Function ) .getType ( ) = t ) and
24+ // Exclude "short" or "long", as opposed to "short int" or "long int".
25+ t instanceof IntType and
26+ // Exclude "signed" or "unsigned", as opposed to "signed int" or "unsigned int".
27+ not exists ( IntegralType it | it = t | it .isExplicitlySigned ( ) or it .isExplicitlyUnsigned ( ) )
28+ )
2129select d , "Declaration is missing a type specifier."
Original file line number Diff line number Diff line change 1- | test.c:2 :8:2 :8 | g | Declaration is missing a type specifier. |
2- | test.c:6 :1:6 :1 | f | Declaration is missing a type specifier. |
1+ | test.c:1 :8:1 :8 | g | Declaration is missing a type specifier. |
2+ | test.c:5 :1:5 :1 | f | Declaration is missing a type specifier. |
Original file line number Diff line number Diff line change 1-
21extern g ; // NON_COMPLIANT
32
43extern int g1 ; // COMPLIANT
@@ -9,4 +8,8 @@ f(void) { // NON_COMPLIANT
98
109int f1 (void ) { // COMPLIANT
1110 return 1 ;
12- }
11+ }
12+
13+ short g2 ; // COMPLIANT
14+ long g3 ; // COMPLIANT
15+ signed g4 () { return 1 ; } // COMPLIANT
You can’t perform that action at this time.
0 commit comments