https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95334
--- Comment #2 from Haoxin Tu <haoxintu at gmail dot com> ---
I also find these cases
test1.cc
#include <iostream>
bool g_bool = 0;
long g_long = -4075183478711827874L;
const long l_long = 7122990940771016367L;
int main () {
g_bool = g_long * l_long;
std::cout << g_bool << std::endl;
return 0;
}
GCC detects nothing.
$g++ -w -fsanitize=signed-integer-overflow test1.cc
1
But when remove "const"
test2.cc
#include <iostream>
bool g_bool = 0;
long g_long = -4075183478711827874L;
const long l_long = 7122990940771016367L;
int main () {
g_bool = g_long * l_long;
std::cout << g_bool << std::endl;
return 0;
}
GCC can dectect the signed-integer-overflow.
$g++ -w -fsanitize=signed-integer-overflow test2.cc
test2.cc:7:21: runtime error: signed integer overflow: -4075183478711827874 *
7122990940771016367 cannot be represented in type 'long int'
1