Title
allocator<>::address
Status
dup
Section
[allocator.members][allocator.requirements][contents]
Submitter
Nathan Myers

Created on 2001-10-25.00:00:00 last changed 171 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

The LWG believes both examples are ill-formed. The contained type is required to be CopyConstructible ([utility.arg.requirements]), and that includes the requirement that &t return the usual types and values. Since allocators are intended to be used in conjunction with containers, and since the CopyConstructible requirements appear to have been written to deal with the concerns of this issue, the LWG feels it is NAD unless someone can come up with a well-formed example exhibiting a problem.

It may well be that the CopyConstructible requirements are too restrictive and that either the container requirements or the CopyConstructive requirements should be relaxed, but that's a far larger issue. Marking this issue as "future" as a pointer to that larger issue.

Date: 2010-10-21.18:28:33

Proposed resolution:

In 20.6.1.1, Change the definition of allocator<>::address from:

Returns: &x

to:

Returns: The value that the built in operator&(x) would return if not overloaded.

In 20.1.6, Table 32, add to the Notes column of the a.address(r) and a.address(s) lines, respectively:

  allocator<T>::address(r)
  allocator<T>::address(s)

In addition, in clause 17.4.1.1, add a statement:

The Standard Library does not apply operator& to any type for which operator& may be overloaded.

Date: 2001-10-25.00:00:00

See c++std-lib-9006 and c++std-lib-9007. This issue is taken verbatim from -9007.

The core language feature allowing definition of operator&() applied to any non-builtin type makes that operator often unsafe to use in implementing libraries, including the Standard Library. The result is that many library facilities fail for legal user code, such as the fragment

  class A { private: A* operator&(); };
  std::vector<A> aa;

  class B { };
  B* operator&(B&) { return 0; }
  std::vector<B> ba;

In particular, the requirements table for Allocator (Table 32) specifies no semantics at all for member address(), and allocator<>::address is defined in terms of unadorned operator &.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2317
2010-10-21 18:28:33adminsetmessages: + msg2316
2001-10-25 00:00:00admincreate