Title
addressof works on temporaries
Status
c++17
Section
[specialized.addressof]
Submitter
Brent Friedman

Created on 2016-03-06.00:00:00 last changed 88 months ago

Messages

Date: 2016-08-03.12:32:27

Proposed resolution:

This wording is relative to N4582.

  1. Change [memory.syn], header <memory> synopsis, as indicated:

    […]
    // 20.9.12, specialized algorithms:
    template <class T> constexpr T* addressof(T& r) noexcept;
    template <class T> const T* addressof(const T&& elem) = delete;
    […]
    
  2. Change [specialized.addressof] p1 as indicated:

    template <class T> constexpr T* addressof(T& r) noexcept;
    template <class T> const T* addressof(const T&& elem) = delete;
    

    -1- Returns: The actual address of the object or function referenced by r, even in the presence of an overloaded operator&.

Date: 2016-08-03.12:32:27

[ 2016-08 Chicago ]

Tues PM: Move to Tentatively Ready

Date: 2016-03-06.00:00:00

LWG issue 970 removed the rvalue reference overload for addressof. This allows const prvalues to bind to a call to addressof, which is dissimilar from the behavior of operator&.

const vector<int> a();

void b()
{
  auto x = addressof(a()); // "ok"
  auto y = addressof<const int>(0); // "ok"
  auto z = &a(); //error: cannot take address of a temporary
}
History
Date User Action Args
2017-07-30 20:15:43adminsetstatus: wp -> c++17
2016-11-14 03:59:28adminsetstatus: pending -> wp
2016-11-14 03:55:22adminsetstatus: ready -> pending
2016-08-03 12:32:27adminsetmessages: + msg8363
2016-08-03 12:32:27adminsetstatus: new -> ready
2016-04-07 21:11:48adminsetmessages: + msg8032
2016-03-06 00:00:00admincreate