Boost C++ Libraries: Ticket #13137: boost::optional::operator*() doesn't have "const &&" overload, allowing incorrect usage https://svn.boost.org/trac10/ticket/13137 <pre class="wiki">#include &lt;boost/optional.hpp&gt; const boost::optional&lt;int&gt; f() { return {1}; } int main() { const int&amp; ref = *f(); // creates a boost::optional temporary // "*tmp" binds to "optional::operator*() const&amp;" // "ref" starts pointing to internals of the returned temporary // temporary gets destroyed // we have a dangling reference } </pre><p> at the same time, std::optional in C++17 does have </p> <pre class="wiki">constexpr const T&amp;&amp; operator*() const &amp;&amp;; </pre><p> <a class="ext-link" href="http://en.cppreference.com/w/cpp/utility/optional/operator*"><span class="icon">​</span>overload</a>, which lets the code above work correctly. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13137 Trac 1.4.3 boost bugs <for.gcc.bugzilla@…> Wed, 26 Jul 2017 06:42:49 GMT <link>https://svn.boost.org/trac10/ticket/13137#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13137#comment:1</guid> <description> <p> the same lack of "() const&amp;&amp;" overload with boost::optional::value() </p> </description> <category>Ticket</category> </item> <item> <author>boost bugs <for.gcc.bugzilla@…></author> <pubDate>Mon, 31 Jul 2017 04:07:55 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/13137#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13137#comment:2</guid> <description> <p> Sorry, I just realised that even if boost::optional::operator*() had such an overload, it still wouldn't fix the problem in the bug description. </p> </description> <category>Ticket</category> </item> </channel> </rss>