Opened 10 years ago

Closed 10 years ago

#1719 closed Bugs (invalid)

[addressof] Can't obtain the address of an instance of an anonymous struct

Reported by: Jean-François Bastien <jfbastien@…> Owned by: Peter Dimov
Milestone: Boost 1.36.0 Component: None
Version: Boost 1.34.1 Severity: Problem
Keywords: Cc:


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.

We're running into an issue with addressof as described at:

Basically this fails under GCC 3.4.4 as well as GCC 4.3:

  struct // NoName
  } noName;

  void * fail()
    return addressof(noName);

The error message is "no matching function for call to `addressof(<anonymous struct>&)'".

MSVC 2005 SP1 compiles and runs this with no problem.

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.

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 &, but this causes a problem in the (unlikely) event where operator char &() is declared in the anonymous struct. We could use template magic to see if operator char &() is declared, but I'm not very comfortable with such a huge workaround.

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.

Change History (2)

comment:1 Changed 10 years ago by Marshall Clow

Owner: set to Peter Dimov

Peter -- if there is someone else who could better address this, please let me know

comment:2 Changed 10 years ago by Peter Dimov

Resolution: invalid
Status: newclosed

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.

Note: See TracTickets for help on using tickets.