Boost C++ Libraries: Ticket #1719: [addressof] Can't obtain the address of an instance of an anonymous struct https://svn.boost.org/trac10/ticket/1719 <p> I sent this to the Boost-users mailing list but got no feedback to validate the issue, but the bottom line is that there's a problem and I'd like addressof to offer a workaround if it's possible. </p> <p> We're running into an issue with addressof as described at: <a class="ext-link" href="https://savannah.cern.ch/bugs/?33071"><span class="icon">​</span>https://savannah.cern.ch/bugs/?33071</a> </p> <p> Basically this fails under GCC 3.4.4 as well as GCC 4.3: </p> <pre class="wiki"> struct // NoName { } noName; void * fail() { return addressof(noName); } </pre><p> The error message is "<code>no matching function for call to `addressof(&lt;anonymous struct&gt;&amp;)'</code>". </p> <p> MSVC 2005 SP1 compiles and runs this with no problem. </p> <p> The problem seems to be that GCC can't deduce the templated type because the struct is anonymous. I'm not sure whether this is because it's non-standard behavior that MSVC accepts and GCC doesn't or because GCC has a bug. </p> <p> Either way it would be nice if addressof had a workaround for the "broken" GCC versions, but I'm not sure what the best workaround would be. Axel suggested in the above link to C-style cast to char &amp;, but this causes a problem in the (unlikely) event where operator char &amp;() is declared in the anonymous struct. We could use template magic to see if operator char &amp;() is declared, but I'm not very comfortable with such a huge workaround. </p> <p> If the discussion points towards a bug in GCC I'll file a bug report with them, but either way addressof isn't working with GCC 3.4.4 and 4.3 (at least), and it would be nice of Boost to offer a workaround. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/1719 Trac 1.4.3 Marshall Clow Thu, 27 Mar 2008 15:09:00 GMT owner set https://svn.boost.org/trac10/ticket/1719#comment:1 https://svn.boost.org/trac10/ticket/1719#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Peter Dimov</span> </li> </ul> <p> Peter -- if there is someone else who could better address this, please let me know </p> Ticket Peter Dimov Mon, 21 Apr 2008 21:53:44 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/1719#comment:2 https://svn.boost.org/trac10/ticket/1719#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">invalid</span> </li> </ul> <p> This is not a bug. The C++ standard says that the unnamed type of noName cannot be used as a template argument. There is nothing that we can do to make addressof work with noName, except possibly making it a macro. </p> Ticket