File tree Expand file tree Collapse file tree
cpp/ql/test/query-tests/Likely Bugs/Arithmetic/ComparisonPrecedence Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ | template.cpp:4:7:4:15 | ... < ... | Check the comparison operator precedence. |
2+ | template.cpp:4:7:4:15 | ... < ... | Check the comparison operator precedence. |
3+ | template.cpp:10:7:10:15 | ... < ... | Check the comparison operator precedence. |
14| test.cpp:42:6:42:14 | ... < ... | Check the comparison operator precedence. |
25| test.cpp:43:6:43:14 | ... > ... | Check the comparison operator precedence. |
36| test.cpp:44:6:44:16 | ... <= ... | Check the comparison operator precedence. |
Original file line number Diff line number Diff line change 1+
2+ template <typename T>
3+ void templateFunc1 (T x, T y, T z) {
4+ if (x < y < z) {} // BAD (though dubious as we can imagine other instantiations using an overloaded `operator<`)
5+ if (x < y && y < z) {} // GOOD
6+ };
7+
8+ template <typename T>
9+ void templateFunc2 (T x, T y, T z) {
10+ if (x < y < z) {} // GOOD (used with an overloaded `operator<`) [FALSE POSITIVE]
11+ if (x < y && y < z) {} // GOOD
12+ };
13+
14+ struct myStruct {
15+ operator bool () {
16+ return true ;
17+ }
18+
19+ myStruct operator <(myStruct &other) {
20+ return other; // non-standard `operator<` behaviour
21+ }
22+ };
23+
24+ int main () {
25+ int x = 3 ;
26+ myStruct y;
27+
28+ templateFunc1 (x, x, x);
29+ templateFunc2 (y, y, y);
30+
31+ return 0 ;
32+ }
You can’t perform that action at this time.
0 commit comments