https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116742
Bug ID: 116742 Summary: -Wuninitialized failed to issue uninitialized variable Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: xiaohuba2021 at 163 dot com Target Milestone: --- The following code WON'T generate any warning with -O2 -Wuninitialized -Wmaybe-uninitialized: ``` #include <iostream> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, s = n; // n is uninitialized cin >> n; cout << s << endl; return 0; } ``` Turning on -Wall -Wextra does not help. However, with `ios_base::sync_with_stdio(false)` and `cin.tie(0)` commented, the compiler will notice that n is uninitialized. g++ version: ``` Using built-in specs. COLLECT_GCC=/opt/compiler-explorer/gcc-snapshot/bin/g++ Target: x86_64-linux-gnu Thread model: posix Supported LTO compression algorithms: zlib gcc version 15.0.0 20240916 (experimental) (Compiler-Explorer-Build-gcc-4f2cd256aace732bff511c59f5871456a564a3a5-binutils-2.42) ``` compiler explorer: https://godbolt.org/z/dWbcjq7vn