From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F0125385AC30; Fri, 25 Jun 2021 10:23:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F0125385AC30 From: "paul.f.fee at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/80635] [9/10 regression] std::optional and bogus -Wmaybe-uninitialized warning Date: Fri, 25 Jun 2021 10:23:12 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 8.2.0 X-Bugzilla-Keywords: diagnostic, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: paul.f.fee at gmail dot com X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 9.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 25 Jun 2021 10:23:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D80635 Paul Fee changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |paul.f.fee at gmail dot com --- Comment #65 from Paul Fee --- Below is some code that produces unexpected -Wmaybe-uninitialized warnings.= Is this a variant of this bug or a separate bug? I've tried a few configurations: Unexpected warnings: $ g++-10 -Wall -O2 warn.cpp -DBOOST warn.cpp: In function =E2=80=98int main()=E2=80=99: warn.cpp:19:10: warning: =E2=80=98*((void*)& i +1)=E2=80=99 may be used uni= nitialized in this function [-Wmaybe-uninitialized] 19 | m_i(i) | ^ warn.cpp:32:10: note: =E2=80=98*((void*)& i +1)=E2=80=99 was declared here 32 | optb i; | ^ No warnings (c++17 flag not needed with GCC 11). $ g++-10 -Wall -O2 warn.cpp -std=3Dc++17=20 $ g++-11 -Wall -O2 warn.cpp -DBOOST $ g++-11 -Wall -O2 warn.cpp=20 The constructor takes three optional and one optional.=20 Adjusting the number and types of parameters makes a difference, but I don't see why. Perhaps with less parameters, passing by register rather than sta= ck memory affects warning generation. However 4 x optional gives= no warning and that would be larger than 3 x optional plus 1 x optional. It's not clear why std::optional would be free from warnings, yet boost::optional not. Is adoption of std::optional an effective way of avoi= ding unnecessary -Wmaybe-uninitialized warnings? It seems that GCC 11 has better behaviour. Is this expected or would some other (perhaps larger) collection of parameters trigger the same warning wi= th GCC 11? If GCC 11 incorporates a specific fix, will that be backported to GCC 10? Tested with GCC on openSUSE Tumbleweed. Package versions: gcc10-c++-10.3.0+git1587-2.1.x86_64 gcc11-c++-11.1.1+git340-1.1.x86_64 The source for warn.cpp: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D #include #ifdef BOOST #include using opts =3D boost::optional; using optb =3D boost::optional; #else #include using opts =3D std::optional; using optb =3D std::optional; #endif class foo { public: foo(opts a, opts b, opts c, optb i) : m_a(a), m_b(b), m_c(c), m_i(i) {} private: opts m_a; opts m_b; opts m_c; optb m_i; }; int main() { opts a, b, c; optb i; foo bar(a, b, c, i); }=