mirror of
https://github.com/github/codeql.git
synced 2026-05-04 13:15:21 +02:00
C++: Add tests for implicit downcast involving references
This commit is contained in:
@@ -2,22 +2,42 @@ typedef struct {
|
||||
int x : 24;
|
||||
} my_struct;
|
||||
|
||||
int getX1(my_struct m) {
|
||||
unsigned int getX1(my_struct m) {
|
||||
return m.x;
|
||||
}
|
||||
|
||||
short getX2(my_struct m) {
|
||||
return m.x;
|
||||
return m.x; // BAD
|
||||
}
|
||||
|
||||
short getX3(my_struct m) {
|
||||
return (short) m.x;
|
||||
return (short) m.x; // GOOD
|
||||
}
|
||||
|
||||
bool getX4(my_struct m) {
|
||||
return m.x;
|
||||
return m.x; // GOOD
|
||||
}
|
||||
|
||||
short getX5(my_struct m) {
|
||||
return (char) m.x;
|
||||
return (char) m.x; // GOOD
|
||||
}
|
||||
|
||||
const char& getx6(my_struct& m) {
|
||||
const char& result = m.x; // BAD [NOT DETECTED]
|
||||
return result;
|
||||
}
|
||||
|
||||
const short& getx7(my_struct& m) {
|
||||
const short& result = (short) m.x; // GOOD
|
||||
return result;
|
||||
}
|
||||
|
||||
const int& getx8(my_struct& m) {
|
||||
const int& result = m.x; // GOOD
|
||||
return result;
|
||||
}
|
||||
|
||||
const bool& getx9(my_struct& m) {
|
||||
const bool& result = m.x; // GOOD
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user