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 1
1
/**
2
2
* @id c/cert/declare-identifiers-before-using-them
3
3
* @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.
5
6
* @kind problem
6
7
* @precision very-high
7
8
* @problem.severity error
@@ -17,5 +18,12 @@ import codingstandards.c.cert
17
18
from Declaration d
18
19
where
19
20
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
+ )
21
29
select 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
-
2
1
extern g ; // NON_COMPLIANT
3
2
4
3
extern int g1 ; // COMPLIANT
@@ -9,4 +8,8 @@ f(void) { // NON_COMPLIANT
9
8
10
9
int f1 (void ) { // COMPLIANT
11
10
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