mirror of
https://github.com/github/codeql.git
synced 2026-05-03 12:45:27 +02:00
CPP: Annotate expr_has_no_effect test.
This commit is contained in:
@@ -5,11 +5,11 @@ int external();
|
||||
class Base {
|
||||
public:
|
||||
virtual int thingy() {
|
||||
1;
|
||||
1; // BAD
|
||||
}
|
||||
|
||||
int our_thingy() {
|
||||
Base::thingy();
|
||||
Base::thingy(); // BAD
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
@@ -17,14 +17,14 @@ public:
|
||||
class Derived : public Base {
|
||||
public:
|
||||
virtual int thingy() {
|
||||
external();
|
||||
external(); // GOOD
|
||||
return 3;
|
||||
}
|
||||
};
|
||||
|
||||
void internal() {
|
||||
Base* ptr = new Derived();
|
||||
ptr->thingy();
|
||||
ptr->thingy(); // GOOD
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
template <typename T>
|
||||
void foo(T x, T y)
|
||||
{
|
||||
x << y;
|
||||
x << y; // GOOD (effect depends on T)
|
||||
};
|
||||
|
||||
struct streamable
|
||||
@@ -15,9 +15,9 @@ void operator<<(streamable& lhs, streamable& rhs)
|
||||
int main()
|
||||
{
|
||||
int x = 3;
|
||||
foo(x, x);
|
||||
foo(x, x); // BAD [NOT DETECTED]
|
||||
streamable y;
|
||||
foo(y, y);
|
||||
foo(y, y); // BAD [NOT DETECTED]
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ int pointless_add_numbers(int lhs, int rhs)
|
||||
void call_add_numbers()
|
||||
{
|
||||
int accum = 0;
|
||||
add_numbers(accum, 4);
|
||||
add_numbers(accum, 10);
|
||||
pointless_add_numbers(accum, 20);
|
||||
add_numbers(accum, 4); // GOOD
|
||||
add_numbers(accum, 10); // GOOD
|
||||
pointless_add_numbers(accum, 20); // BAD
|
||||
}
|
||||
|
||||
@@ -6,18 +6,18 @@ char *pc;
|
||||
volatile char *pv;
|
||||
|
||||
void f(void) {
|
||||
c;
|
||||
v;
|
||||
c; // BAD
|
||||
v; // (accesses to volatile variables are considered impure)
|
||||
|
||||
pc[5];
|
||||
pc[5]; // BAD
|
||||
pv[5];
|
||||
((volatile char *)pc)[5];
|
||||
|
||||
*pc;
|
||||
*pc; // BAD
|
||||
*pv;
|
||||
*((volatile char *)pc);
|
||||
|
||||
*(pc + 5);
|
||||
*(pc + 5); // BAD
|
||||
*(pv + 5);
|
||||
*((volatile char *)(pc + 5));
|
||||
*(((volatile char *)pc) + 5);
|
||||
|
||||
Reference in New Issue
Block a user