From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9F1D83851C0C; Wed, 27 May 2020 01:26:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9F1D83851C0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1590542773; bh=4HCaff4U9bUKaDh10tS7sKJs7r/uPaX+aT+P9irsL0c=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WyMBLvn9rVklTDMaBTerBOsL32t0AUvQttoH+Ie4hLTzjz/IpmSpGaRfVsNPzFV7A v1vKABIImgPdzKIWr2kvujMm+eaZwk0Y3TvyohRxbDRJckvxazVr4J26Az515U6R9U XUv4qIPYLodtNSe4gnfRETQquGg/nV3wDZDAGmPg= From: "haoxintu at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/95334] GCC detect missing signed-integer-overflow when add "const" Date: Wed, 27 May 2020 01:26:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: haoxintu at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 May 2020 01:26:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95334 --- Comment #2 from Haoxin Tu --- I also find these cases test1.cc #include bool g_bool =3D 0; long g_long =3D -4075183478711827874L; const long l_long =3D 7122990940771016367L; int main () { g_bool =3D g_long * l_long; std::cout << g_bool << std::endl; return 0; } GCC detects nothing. $g++ -w -fsanitize=3Dsigned-integer-overflow test1.cc 1 But when remove "const" test2.cc #include bool g_bool =3D 0; long g_long =3D -4075183478711827874L; const long l_long =3D 7122990940771016367L; int main () { g_bool =3D g_long * l_long; std::cout << g_bool << std::endl; return 0; } GCC can dectect the signed-integer-overflow. $g++ -w -fsanitize=3Dsigned-integer-overflow test2.cc test2.cc:7:21: runtime error: signed integer overflow: -4075183478711827874= * 7122990940771016367 cannot be represented in type 'long int' 1=