@@ -17,22 +17,35 @@ import codingstandards.c.misra
1717import codingstandards.cpp.Linkage
1818
1919class 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+ }
2131
2232 string getSignificantName ( ) {
2333 //C99 states the first 31 characters of external identifiers are significant
2434 //C90 states the first 6 characters of external identifiers are significant and case is not required to be significant
2535 //C90 is not currently considered by this rule
2636 result = this .getName ( ) .prefix ( 31 )
2737 }
38+
39+ string getNonSignificantName ( ) { result = this .getName ( ) .suffix ( 31 ) }
2840}
2941
3042from ExternalIdentifiers d , ExternalIdentifiers d2
3143where
3244 not isExcluded ( d , Declarations1Package:: externalIdentifiersNotDistinctQuery ( ) ) and
3345 not d = d2 and
3446 d .getLocation ( ) .getStartLine ( ) >= d2 .getLocation ( ) .getStartLine ( ) and
35- d .getSignificantName ( ) = d2 .getSignificantName ( )
47+ d .getSignificantName ( ) = d2 .getSignificantName ( ) and
48+ not d .getNonSignificantName ( ) = d2 .getNonSignificantName ( )
3649select d ,
3750 "External identifer " + d .getName ( ) + " is nondistinct in first 31 characters, compared to $@." ,
3851 d2 , d2 .getName ( )
0 commit comments