mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Warn about shift of literals.
This commit is contained in:
@@ -1765,6 +1765,44 @@ BOOST_AUTO_TEST_CASE(exp_warn_literal_base)
|
||||
CHECK_SUCCESS(sourceCode);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(shift_warn_literal_base)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract test {
|
||||
function f() returns(uint) {
|
||||
uint8 x = 100;
|
||||
return 10 << x;
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_WARNING(sourceCode, "might overflow");
|
||||
sourceCode = R"(
|
||||
contract test {
|
||||
function f() returns(uint) {
|
||||
uint8 x = 100;
|
||||
return uint8(10) << x;
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(sourceCode);
|
||||
sourceCode = R"(
|
||||
contract test {
|
||||
function f() returns(uint) {
|
||||
return 2 << 80;
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(sourceCode);
|
||||
sourceCode = R"(
|
||||
contract test {
|
||||
function f() returns(uint) {
|
||||
uint8 x = 100;
|
||||
return 10 >> x;
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(sourceCode);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(warn_var_from_zero)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user