|
20 | 20 |
|
21 | 21 | import cpp |
22 | 22 | import codingstandards.cpp.autosar |
23 | | -import codingstandards.cpp.AcceptableHeader |
| 23 | +import codingstandards.cpp.rules.violationsofonedefinitionrule.ViolationsOfOneDefinitionRule |
24 | 24 |
|
25 | | -predicate isInline(Function decl) { |
26 | | - exists(Specifier spec | |
27 | | - spec = decl.getASpecifier() and |
28 | | - ( |
29 | | - spec.hasName("inline") or |
30 | | - spec.hasName("constexpr") |
31 | | - ) |
32 | | - ) |
| 25 | +class ViolationsOfOneDefinitionRuleQuery extends ViolationsOfOneDefinitionRuleSharedQuery { |
| 26 | + ViolationsOfOneDefinitionRuleQuery() { |
| 27 | + this = IncludesPackage::violationsOfOneDefinitionRuleQuery() |
| 28 | + } |
33 | 29 | } |
34 | | - |
35 | | -predicate isExtern(FunctionDeclarationEntry decl) { |
36 | | - exists(string spec | |
37 | | - spec = decl.getASpecifier() and |
38 | | - spec = "extern" |
39 | | - ) |
40 | | -} |
41 | | - |
42 | | -from DeclarationEntry decl, string case, string name |
43 | | -where |
44 | | - ( |
45 | | - //a non-inline/non-extern function defined in a header |
46 | | - exists(FunctionDeclarationEntry fn | |
47 | | - fn.isDefinition() and |
48 | | - not ( |
49 | | - isInline(fn.getDeclaration()) |
50 | | - or |
51 | | - isExtern(fn) |
52 | | - or |
53 | | - //any (defined) templates do not violate the ODR |
54 | | - fn.isFromUninstantiatedTemplate(_) |
55 | | - or |
56 | | - fn.isFromTemplateInstantiation(_) and |
57 | | - //except for specializations, those do violate ODR |
58 | | - not fn.isSpecialization() |
59 | | - or |
60 | | - fn.getDeclaration().isStatic() |
61 | | - ) and |
62 | | - decl = fn and |
63 | | - case = "function" |
64 | | - ) |
65 | | - or |
66 | | - //an non-const object defined in a header |
67 | | - exists(GlobalOrNamespaceVariable object | |
68 | | - object.hasDefinition() and |
69 | | - not ( |
70 | | - object.isConstexpr() |
71 | | - or |
72 | | - object.isConst() |
73 | | - or |
74 | | - object.isStatic() |
75 | | - ) and |
76 | | - decl = object.getDefinition() and |
77 | | - case = "object" |
78 | | - ) |
79 | | - ) and |
80 | | - not decl.getDeclaration().getNamespace().isAnonymous() and |
81 | | - decl.getFile() instanceof AcceptableHeader and |
82 | | - not isExcluded(decl, IncludesPackage::violationsOfOneDefinitionRuleQuery()) and |
83 | | - name = decl.getName() |
84 | | -select decl, |
85 | | - "Header file $@ contains " + case + " " + name + " that lead to One Defintion Rule violation.", |
86 | | - decl.getFile(), decl.getFile().getBaseName() |
0 commit comments