Bug 55039 - std::addressof vs. constexpr
Summary: std::addressof vs. constexpr
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2012-10-23 18:12 UTC by Benjamin Kosnik
Modified: 2016-10-10 17:22 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-06-29 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Benjamin Kosnik 2012-10-23 18:12:16 UTC
If std::addressof can be made constexpr, then the iterator member functions of std::array should be able to be made constexpr as well (begin/end, etc.)

As it stands, std::addressof calls into std::__addressof, which has a reinterpret_cast, killing constexpr. 

If some variation of

http://gcc.gnu.org/onlinedocs/gcc/Return-Address.html

could be extended to support this, then the new intrinsic could be used to implement std::addressof.
Comment 1 Daniel Krügler 2012-10-23 18:15:38 UTC
I agree, an intrinsic is needed
Comment 2 Paolo Carlini 2012-10-23 20:53:41 UTC
Daniel, I'm confused: didn't we agree in that other open PR we have got about reinterpret_cast vs constexpr that actually the Standard should be amended exactly to allow this meaningful use of reint cast in the impl of address_of?
Comment 3 Daniel Krügler 2012-10-23 20:56:36 UTC
(In reply to comment #2)
During the Portland meeting the issue

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1384

was discussed and core had consensus *not* to support reinterpret_cast in constant core expressions. I think this means we need to bite the bullet now.
Comment 4 Paolo Carlini 2012-10-23 21:06:09 UTC
Ok, thanks, I wasn't there. Then please somebody add a note to that other PR. In any case, the other PR being about us actually accepting reint casts for the time being, I think it's Ok for our library to just constexpr for the time being and add a big comment about this PR, that is about the eventual need of an intrinsics as implementation detail.
Comment 5 Jason Merrill 2014-11-17 20:54:57 UTC
Since LWG decided not to allow implementations to add constexpr (sigh), I guess we don't need this intrinsic.
Comment 6 Daniel Krügler 2014-11-17 20:58:29 UTC
(In reply to Jason Merrill from comment #5)

Given that there exists the still open issue

http://cplusplus.github.io/LWG/lwg-active.html#2296

should this bugzilla issue remain open?
Comment 7 Marc Glisse 2014-11-17 21:26:40 UTC
std::addressof can be constexpr with -std=gnu++XX, and even in strict mode std::__addressof can be constexpr for internal use in libstdc++.
Comment 8 Jonathan Wakely 2016-06-29 19:21:44 UTC
Although implementations can't add constexpr in general, LWG decided that they are required to add it to std::addressof:

http://cplusplus.github.io/LWG/lwg-defects.html#2296

So confirming as a required feature.
Comment 9 Jonathan Wakely 2016-10-10 17:22:52 UTC
r240873 added __builtin_addressof and r240929 made std::addressof use it.