The following snippet looks legal to me, but it does not compile:

#include <list>

struct aaa {};

struct bbb {

  aaa operator & ( void ) const {
    return aaa();
  }

};

bool operator< ( bbb lhs, bbb rhs ) {
  return ( false );
}

int main ( void ) {
  std::list< bbb > a;
}


I run into the same problem with the containers std::vector, std::deque, and
std::set. It appears that while calling the allocator functions construct() and
destroy(), the library uses operator& to figure out an address and overloading
that operator triggers a problem. I venture the conjecture that one could also
conjure programs that will compile but exhibit strange behavior by using, e.g.,

  bbb* operator& ( void ) const {
    return 0;
  }

But I have not tested this.

In any case, I don't recall a conceptual requirement from the standard saying
that datatypes to be used in list<> have to have a sane operator&.


Best

Kai-Uwe Bux


-- 
           Summary: overloading the address operator confuses the standard
                    containers
           Product: gcc
           Version: 4.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jkherciueh at gmx dot net
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41792

Reply via email to