public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream
@ 2022-05-27 10:13 hi+gccbugs at yamlcoder dot me
2022-06-22 20:20 ` [Bug tree-optimization/105749] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: hi+gccbugs at yamlcoder dot me @ 2022-05-27 10:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105749
Bug ID: 105749
Summary: Bogus maybe-unitialized when using std::optional,
regex and sstream
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: hi+gccbugs at yamlcoder dot me
Target Milestone: ---
Created attachment 53044
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53044&action=edit
t.ii reproducer
Compiling following with -Wall -Werror -Os produces bogus
maybe-unitialized warning
/tmp/t.cpp: In function ‘void t(const string&)’:
/tmp/t.cpp:12:51: error: ‘*(int*)((char*)&port +
offsetof(std::optional<int>,std::optional<int>::<unnamed>.std::_Optional_base<int,
true, true>::<unnamed>))’ may be used uninitialized in this function
[-Werror=maybe-uninitialized]
12 | reqb << "Host: " << port.value_or(443) << "\r\n";
Attaching .ii (tar.gz due to attachment limit) file from 11.2.0, but it is also
reproducible on trunk in godbolt: https://godbolt.org/z/ha3vn61n9
Interesting that commenting unrelated parts or changing them slightly makes
warning go away.
#include <regex>
#include <optional>
#include <sstream>
void t(const std::string& i) {
const std::regex re("^$"); //removing this works
std::optional<int> port(i.length() > 0 ?
std::make_optional(std::strtol("99", nullptr, 10)) : std::nullopt);
std::ostringstream reqb;
reqb << "GET /" << i << " HTTP/1.1" << "\r\n"; //removing this works
reqb << "Host: " << port.value_or(443) << "\r\n";
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/105749] Bogus maybe-unitialized when using std::optional, regex and sstream
2022-05-27 10:13 [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream hi+gccbugs at yamlcoder dot me
@ 2022-06-22 20:20 ` pinskia at gcc dot gnu.org
2022-06-22 20:23 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-22 20:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105749
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>Interesting that commenting unrelated parts or changing them slightly makes
warning go away.
Most likely inlining changes with those being there vs not being there.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/105749] Bogus maybe-unitialized when using std::optional, regex and sstream
2022-05-27 10:13 [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream hi+gccbugs at yamlcoder dot me
2022-06-22 20:20 ` [Bug tree-optimization/105749] " pinskia at gcc dot gnu.org
@ 2022-06-22 20:23 ` pinskia at gcc dot gnu.org
2022-06-22 20:24 ` pinskia at gcc dot gnu.org
2022-09-22 13:25 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-22 20:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105749
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
<source>: In function 'void t(const std::string&)':
<source>:13:51: warning: '*(int*)((char*)&port +
offsetof(std::optional<int>,std::optional<int>::<unnamed>.std::_Optional_base<int,
true, true>::<unnamed>))' may be used uninitialized [-Wmaybe-uninitialized]
13 | reqb << "Host: " << port.value_or(443) << "\r\n";
| ^~~~~~
<source>:9:28: note: '*(int*)((char*)&port +
offsetof(std::optional<int>,std::optional<int>::<unnamed>.std::_Optional_base<int,
true, true>::<unnamed>))' was declared here
9 | std::optional<int> port(i.length() > 0 ?
std::make_optional(std::strtol("99", nullptr, 10)) : std::nullopt);
| ^~~~
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/105749] Bogus maybe-unitialized when using std::optional, regex and sstream
2022-05-27 10:13 [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream hi+gccbugs at yamlcoder dot me
2022-06-22 20:20 ` [Bug tree-optimization/105749] " pinskia at gcc dot gnu.org
2022-06-22 20:23 ` pinskia at gcc dot gnu.org
@ 2022-06-22 20:24 ` pinskia at gcc dot gnu.org
2022-09-22 13:25 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-06-22 20:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105749
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |10.3.0
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note in GCC 10.3.0 we got:
<source>: In function 'void t(const string&)':
<source>:13:51: warning: 'port' may be used uninitialized in this function
[-Wmaybe-uninitialized]
13 | reqb << "Host: " << port.value_or(443) << "\r\n";
| ^~~~~~
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/105749] Bogus maybe-unitialized when using std::optional, regex and sstream
2022-05-27 10:13 [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream hi+gccbugs at yamlcoder dot me
` (2 preceding siblings ...)
2022-06-22 20:24 ` pinskia at gcc dot gnu.org
@ 2022-09-22 13:25 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-09-22 13:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105749
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Known to fail| |12.2.1, 13.0
Last reconfirmed| |2022-09-22
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed on the GCC 12 branch but on master the diagnostic only shows with -O1
now ...
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-09-22 13:25 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-27 10:13 [Bug c++/105749] New: Bogus maybe-unitialized when using std::optional, regex and sstream hi+gccbugs at yamlcoder dot me
2022-06-22 20:20 ` [Bug tree-optimization/105749] " pinskia at gcc dot gnu.org
2022-06-22 20:23 ` pinskia at gcc dot gnu.org
2022-06-22 20:24 ` pinskia at gcc dot gnu.org
2022-09-22 13:25 ` rguenth at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).