@@ -17,22 +17,35 @@ import codingstandards.c.misra
17
17
import codingstandards.cpp.Linkage
18
18
19
19
class ExternalIdentifiers extends Declaration {
20
- ExternalIdentifiers ( ) { hasExternalLinkage ( this ) }
20
+ ExternalIdentifiers ( ) {
21
+ this .getName ( ) .length ( ) > 31 and
22
+ hasExternalLinkage ( this ) and
23
+ getNamespace ( ) instanceof GlobalNamespace and
24
+ not this .isFromTemplateInstantiation ( _) and
25
+ not this .isFromUninstantiatedTemplate ( _) and
26
+ not this .hasDeclaringType ( ) and
27
+ not this instanceof UserType and
28
+ not this instanceof Operator and
29
+ not this .hasName ( "main" )
30
+ }
21
31
22
32
string getSignificantName ( ) {
23
33
//C99 states the first 31 characters of external identifiers are significant
24
34
//C90 states the first 6 characters of external identifiers are significant and case is not required to be significant
25
35
//C90 is not currently considered by this rule
26
36
result = this .getName ( ) .prefix ( 31 )
27
37
}
38
+
39
+ string getNonSignificantName ( ) { result = this .getName ( ) .suffix ( 31 ) }
28
40
}
29
41
30
42
from ExternalIdentifiers d , ExternalIdentifiers d2
31
43
where
32
44
not isExcluded ( d , Declarations1Package:: externalIdentifiersNotDistinctQuery ( ) ) and
33
45
not d = d2 and
34
46
d .getLocation ( ) .getStartLine ( ) >= d2 .getLocation ( ) .getStartLine ( ) and
35
- d .getSignificantName ( ) = d2 .getSignificantName ( )
47
+ d .getSignificantName ( ) = d2 .getSignificantName ( ) and
48
+ not d .getNonSignificantName ( ) = d2 .getNonSignificantName ( )
36
49
select d ,
37
50
"External identifer " + d .getName ( ) + " is nondistinct in first 31 characters, compared to $@." ,
38
51
d2 , d2 .getName ( )
0 commit comments