Boost C++ Libraries: Ticket #11169: boost::optional triggers -Wmaybe-uninitialized errors in g++ https://svn.boost.org/trac10/ticket/11169 <p> Example taken from <a class="missing wiki">StackOverflow</a> question 21755206* </p> <pre class="wiki">#include &lt;boost/optional.hpp&gt; ::boost::optional&lt;int&gt; getitem(); int go(int nr) { boost::optional&lt;int&gt; a = getitem(); boost::optional&lt;int&gt; b; if (nr &gt; 0) b = nr; if (a != b) return 1; return 0; } </pre><pre class="wiki">g++ -c -O2 -Wall /tmp/test.cpp /tmp/test.cpp: In function β€˜int go(int)’ /tmp/test.cpp:13:3: warning: β€˜*((void*)&amp; b +4)’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (a != b) ^ </pre><p> This has been reported as gcc bug 47679*. </p> <p> Two workarounds that seem to work in my testing are value-initializing dummy_ in the aligned_storage default constructor or adding an empty asm statement that lists dummy_ as an output. Would it be possible to include a fix in mainline boost? </p> <ul><li>Sorry, but trac flags this as spam if I include direct links. </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11169 Trac 1.4.3 akrzemi1 Mon, 15 Feb 2016 12:25:02 GMT <link>https://svn.boost.org/trac10/ticket/11169#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11169#comment:1</guid> <description> <p> Could you give me an example of such an asm statement? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 19 Sep 2016 07:38:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11169#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11169#comment:2</guid> <description> <p> Note that this GCC bug is fixed in GCC 5.1. Also as per th <a class="missing wiki">StackOverflow</a> response, use a workaround by initializing an optional with a 'fabricated' empty value: </p> <pre class="wiki">boost::optional&lt;int&gt; b = boost::make_opitonal(false, int()); </pre> </description> <category>Ticket</category> </item> </channel> </rss>