https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108780
Bug ID: 108780 Summary: Spurious warning with -ftrivial-auto-var-init=zero Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: trprince at synopsys dot com Target Milestone: --- I encountered the following spurious (or at least, confusing/misleading--note the variable name) warning on some code after enabling `-ftrivial-auto-var-init=zero` on one of our codebases. It appears that there have been similar issues with spurious warnings and `-ftrivial-auto-var-init=zero` in the past but I was able to reproduce this with trunk on godbolt: https://godbolt.org/z/zre74sWq1 $ cat bad.cpp struct a { int b(); }; void c() { a d; const auto &e(d.b()); } $ g++ --version g++ (GCC) 12.1.0 Copyright (C) 2022 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++ -ftrivial-auto-var-init=zero -Wuninitialized -c bad.cpp bad.cpp: In function ‘void c()’: bad.cpp:6:22: warning: ‘D.2414’ is used uninitialized [-Wuninitialized] 6 | const auto &e(d.b()); | ^ $ I'd be happy to provide any additional context if I'm missing anything.