public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "MikeSmith32564 at mail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113111] New: -Werror=uninitialized is not consistent for optimization level 0 or -std=before-c++20 Date: Fri, 22 Dec 2023 08:15:26 +0000 [thread overview] Message-ID: <bug-113111-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113111 Bug ID: 113111 Summary: -Werror=uninitialized is not consistent for optimization level 0 or -std=before-c++20 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: MikeSmith32564 at mail dot com Target Milestone: --- The following snippet: #include <string> #include <iostream> struct Dummy { std::string val; }; int main() { Dummy d = { d.val = "random text #########################################################" }; std::cout<<d.val<<"\n"; } when built with: g++ -std=c++20 -O0 -Wall -Werror main.cpp -o a.out should generate a warning a.k.a. compilation error due to -Werror about trying to assign from an uninitialized variable. When -O1, -O2 or -O3 are used the expected warning is shown: include/c++/14.0.0/bits/basic_string.h:1084:16: error: 'd.Dummy::val.std::__cxx11::basic_string<char>::_M_string_length' is used uninitialized [-Werror=uninitialized] 1084 | { return _M_string_length; } | ^~~~~~~~~~~~~~~~ The example triggers undefined behavior when executed of course due to running std::string::operator= with the this pointer pointing to uninitialized memory but I believe a warning should be raised when building regardless of the optimization level selected. Strangely, standards before c++20 also do not report the warning.
next reply other threads:[~2023-12-22 8:15 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-12-22 8:15 MikeSmith32564 at mail dot com [this message] 2024-01-18 19:23 ` [Bug c++/113111] " mpolacek at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-113111-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).