File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
cpp/ql/test/query-tests/jsf/4.10 Classes/AV Rule 82 Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,43 @@ class AlwaysThrows {
133133 }
134134};
135135
136+ class Reachability {
137+ Reachability &operator =(Reachability &that) { // GOOD [FALSE POSITIVE]
138+ int one = 1 ;
139+ if (one)
140+ return *this ;
141+ else
142+ return that; // unreachable
143+ }
144+
145+ // helper function that always returns a reference to `*this`.
146+ Reachability &returnThisReference () {
147+ int one = 1 ;
148+ if (one)
149+ return *this ;
150+ else
151+ return staticInstance; // unreachable
152+ }
153+
154+ // helper function that always returns `this`.
155+ Reachability *const returnThisPointer () {
156+ int one = 1 ;
157+ if (one)
158+ return this ;
159+ else
160+ return &staticInstance; // unreachable
161+ }
162+
163+ Reachability &operator =(int _val) { // GOOD [FALSE POSITIVE]
164+ return returnThisReference ();
165+ }
166+
167+ Reachability &operator =(short _val) { // GOOD [FALSE POSITIVE]
168+ return *returnThisPointer ();
169+ }
170+
171+ static Reachability staticInstance;
172+ };
136173
137174int main () {
138175 Container c;
Original file line number Diff line number Diff line change 22| AV Rule 82.cpp:24:8:24:16 | operator= | Assignment operator in class Bad2 should have return type Bad2&. Otherwise a copy is created at each call. |
33| AV Rule 82.cpp:63:29:63:37 | operator= | Assignment operator in class TemplateReturnAssignment<T> does not return a reference to *this. |
44| AV Rule 82.cpp:63:29:63:37 | operator= | Assignment operator in class TemplateReturnAssignment<int> does not return a reference to *this. |
5+ | AV Rule 82.cpp:137:17:137:25 | operator= | Assignment operator in class Reachability does not return a reference to *this. |
6+ | AV Rule 82.cpp:163:17:163:25 | operator= | Assignment operator in class Reachability does not return a reference to *this. |
7+ | AV Rule 82.cpp:167:17:167:25 | operator= | Assignment operator in class Reachability does not return a reference to *this. |
You can’t perform that action at this time.
0 commit comments