|
16 | 16 |
|
17 | 17 | import cpp
|
18 | 18 | import codingstandards.c.cert
|
| 19 | +import codingstandards.cpp.Compatible |
19 | 20 | import ExternalIdentifiers
|
20 | 21 |
|
21 |
| -//checks if they are incompatible based on return type, number of parameters and parameter types |
22 |
| -predicate checkMatchingFunction(FunctionDeclarationEntry d, FunctionDeclarationEntry d2) { |
23 |
| - not d.getType() = d2.getType() |
24 |
| - or |
25 |
| - not d.getNumberOfParameters() = d2.getNumberOfParameters() |
26 |
| - or |
27 |
| - exists(ParameterDeclarationEntry p, ParameterDeclarationEntry p2, int i | |
28 |
| - d.getParameterDeclarationEntry(i) = p and |
29 |
| - d2.getParameterDeclarationEntry(i) = p2 and |
30 |
| - not p.getType() = p2.getType() |
31 |
| - ) |
32 |
| -} |
33 |
| - |
34 | 22 | from ExternalIdentifiers d, FunctionDeclarationEntry f1, FunctionDeclarationEntry f2
|
35 | 23 | where
|
36 | 24 | not isExcluded(f1, Declarations2Package::incompatibleFunctionDeclarationsQuery()) and
|
37 | 25 | not isExcluded(f2, Declarations2Package::incompatibleFunctionDeclarationsQuery()) and
|
38 |
| - f1 = d.getADeclarationEntry() and |
39 |
| - f2 = d.getADeclarationEntry() and |
40 | 26 | not f1 = f2 and
|
41 |
| - f1.getLocation().getStartLine() >= f2.getLocation().getStartLine() and |
| 27 | + f1.getDeclaration() = d and |
| 28 | + f2.getDeclaration() = d and |
42 | 29 | f1.getName() = f2.getName() and
|
43 |
| - checkMatchingFunction(f1, f2) |
| 30 | + ( |
| 31 | + //return type check |
| 32 | + not typesCompatible(f1.getType(), f2.getType()) |
| 33 | + or |
| 34 | + //parameter type check |
| 35 | + parameterTypesIncompatible(f1, f2) |
| 36 | + or |
| 37 | + not f1.getNumberOfParameters() = f2.getNumberOfParameters() |
| 38 | + ) and |
| 39 | + // Apply ordering on start line, trying to avoid the optimiser applying this join too early |
| 40 | + // in the pipeline |
| 41 | + exists(int f1Line, int f2Line | |
| 42 | + f1.getLocation().hasLocationInfo(_, f1Line, _, _, _) and |
| 43 | + f2.getLocation().hasLocationInfo(_, f2Line, _, _, _) and |
| 44 | + f1Line >= f2Line |
| 45 | + ) |
44 | 46 | select f1, "The object $@ is not compatible with re-declaration $@", f1, f1.getName(), f2,
|
45 | 47 | f2.getName()
|
0 commit comments