C++: Test that range analysis ignores references

This commit is contained in:
Jonas Jensen
2020-08-28 14:38:36 +02:00
parent a3a3423db2
commit 027f22d8e7

View File

@@ -78,3 +78,25 @@ void use_after_cast(unsigned char c)
}
c_times_2;
}
int ref_to_number(int &i, const int &ci, int &aliased) {
int &alias = aliased; // no range analysis for either of the two aliased variables
if (i >= 2)
return i; // BUG: lower bound should be 2
if (ci >= 2)
return ci; // BUG: lower bound should be 2
if (aliased >= 2)
return aliased;
if (alias >= 2)
return alias;
for (; i <= 12345; i++) {
i; // BUG: upper bound should be deduced (but subject to widening)
}
return 0;
}