Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95e457c

Browse files
committed
C++: Add test with FP in ExprHasNoEffect
1 parent 28261d6 commit 95e457c

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
| test.cpp:25:3:25:3 | call to operator++ | This expression has no effect (because $@ has no external side effects). | test.cpp:9:14:9:23 | operator++ | operator++ |
3030
| test.cpp:62:5:62:5 | call to operator= | This expression has no effect (because $@ has no external side effects). | test.cpp:47:14:47:22 | operator= | operator= |
3131
| test.cpp:65:5:65:5 | call to operator= | This expression has no effect (because $@ has no external side effects). | test.cpp:55:7:55:7 | operator= | operator= |
32+
| test.cpp:91:5:91:19 | call to operator= | This expression has no effect (because $@ has no external side effects). | test.cpp:77:9:77:17 | operator= | operator= |
3233
| volatile.c:9:5:9:5 | c | This expression has no effect. | volatile.c:9:5:9:5 | c | |
3334
| volatile.c:12:5:12:9 | access to array | This expression has no effect. | volatile.c:12:5:12:9 | access to array | |
3435
| volatile.c:16:5:16:7 | * ... | This expression has no effect. | volatile.c:16:5:16:7 | * ... | |

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/test.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,45 @@ void testFunc2()
6464
MyAssignable v1, v2;
6565
v2 = v1;
6666
}
67+
68+
namespace std {
69+
typedef unsigned long size_t;
70+
}
71+
72+
void* operator new (std::size_t size, void* ptr) noexcept;
73+
74+
struct Base {
75+
Base() { }
76+
77+
Base &operator=(const Base &rhs) {
78+
return *this;
79+
}
80+
81+
virtual ~Base() { }
82+
};
83+
84+
struct Derived : Base {
85+
Derived &operator=(const Derived &rhs) {
86+
if (&rhs == this) {
87+
return *this;
88+
}
89+
90+
// In case base class has data, now or in the future, copy that first.
91+
Base::operator=(rhs); // GOOD [FALSE POSITIVE]
92+
93+
this->m_x = rhs.m_x;
94+
return *this;
95+
}
96+
97+
int m_x;
98+
};
99+
100+
void use_Base() {
101+
Base base_buffer[1];
102+
Base *base = new(&base_buffer[0]) Base();
103+
104+
// In case the destructor does something, now or in the future, call it. It
105+
// won't get called automatically because the object was allocated with
106+
// placement new.
107+
base->~Base(); // GOOD (because the call has void type)
108+
}

0 commit comments

Comments
 (0)