https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95656
Bug ID: 95656 Summary: Inconsistent output in compiling an undefined function Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: haoxintu at gmail dot com Target Milestone: --- This code bug.cc #include<iostream> int main(){ int a (); std::cout << a << std::endl; return 0; } In GCC-trunk without "-fsanitize=undefined" $g++ bug.cc ; ./a.out 1 $g++-trunk -fsanitize=undefined bug.cc /tmp/ccm15L4R.o: In function `main': bug.cc:(.text+0x8f): undefined reference to `a()' collect2: error: ld returned 1 exit status While in GCC-5 $g++-5 bug.cc ; ./a.out 1 $g++-5 -fsanitize=undefined bug.cc ; ./a.out 1 My GCC versions are $g++-trunk --version g++ (GCC) 11.0.0 20200526 (experimental) Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $g++-5 --version g++-5 (Ubuntu 5.5.0-12ubuntu6~18.04) 5.5.0 20171010 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. I also tested bug.cc in clang, it compiles well and output "1" whether adding "-fsanitize=undefined" or not.