From 3d595d4b149e590138f35a6f535c0a20a28e6f04 Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 16 Aug 2017 13:52:06 +0200 Subject: Warn about shift of literals. --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'test/libsolidity') diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 51d60596..1c83e1a3 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -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) { -- cgit