mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Merge pull request #2295 from jbj/self-comparison-templates
C++: Suppress PointlessSelfComparison.ql on templates
This commit is contained in:
@@ -19,6 +19,7 @@ where
|
||||
pointlessSelfComparison(cmp) and
|
||||
not nanTest(cmp) and
|
||||
not overflowTest(cmp) and
|
||||
not cmp.isFromTemplateInstantiation(_) and
|
||||
not exists(MacroInvocation mi |
|
||||
// cmp is in mi
|
||||
mi.getAnExpandedElement() = cmp and
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
| templates.cpp:17:5:17:25 | ... < ... | Self comparison. |
|
||||
| test.cpp:13:11:13:21 | ... == ... | Self comparison. |
|
||||
| test.cpp:79:11:79:32 | ... == ... | Self comparison. |
|
||||
| test.cpp:83:10:83:15 | ... == ... | Self comparison. |
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
struct C1 {
|
||||
static const int value = 5;
|
||||
};
|
||||
|
||||
struct C2 {
|
||||
static const int value = 6;
|
||||
};
|
||||
|
||||
template<typename T1, typename T2>
|
||||
bool compareValues() {
|
||||
// Not all instantiations have T1 and T2 equal. Even if that's the case for
|
||||
// all instantiations in the program, there could still be more such
|
||||
// instantiations outside.
|
||||
return
|
||||
T1::value < T2::value || // GOOD
|
||||
T1::value < T1::value || // BAD [NOT DETECTED]
|
||||
C1::value < C1::value ; // BAD
|
||||
}
|
||||
|
||||
bool callCompareValues() {
|
||||
return compareValues<C1, C2> || compareValues<C1, C1>();
|
||||
}
|
||||
Reference in New Issue
Block a user