https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125777
Bug ID: 125777
Summary: [13/14/15/16/17 Regression] false positive of
-Wmaybe-uninitialized using -Os
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: fabio.porcedda at gmail dot com
Target Milestone: ---
Created attachment 64729
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64729&action=edit
Code to reproduce the issue
There is a false positive when using from_chars and -Os:
$ g++ -Os -Wall -c test.cpp
test.cpp: In function ‘int getInt(std::string)’:
test.cpp:13:12: warning: ‘result’ may be used uninitialized
[-Wmaybe-uninitialized]
13 | return result;
| ^~~~~~
test.cpp:6:9: note: ‘result’ was declared here
6 | int result;
| ^~~~~~
When using -Os it doesn't understand that when from_chars returns std::errc{}
the return values was initialized.
This warning is not present using other optimizations like -O2.
The issue is not present in 12 but in later versions.
Tested on trunk, 16.1, 15.2, 14.3, 13.4, 12.5.
Code available in as attachment as also in https://godbolt.org/z/9j4413Mcc