Re: [RFC] Implementing addressof for C++0x
... for reference, it would be something like this (in my recollections, it was even uglier ;) templatetypename _Tp _Tp* addressof(_Tp __v) { return reinterpret_cast_Tp* (const_castchar(reinterpret_castconst volatile char(__v))); } I'm not sure... Paolo.
Re: [RFC] Implementing addressof for C++0x
On 05/20/2010 01:10 PM, Paolo Carlini wrote: ... for reference, it would be something like this (in my recollections, it was even uglier ;) templatetypename _Tp _Tp* addressof(_Tp __v) { return reinterpret_cast_Tp* (const_castchar(reinterpret_castconst volatile char(__v))); } By the way, Peter (I think you are the author of the current boost implementation, which I looked at yesterday), in case we end up having something like the above, temporarily at least, which kind of acknowledgment would you be Ok with? Is it enough your name in the ChangeLog? Thanks, Paolo.
Re: [RFC] Implementing addressof for C++0x
On 05/20/2010 01:10 PM, Paolo Carlini wrote: ... for reference, it would be something like this (in my recollections, it was even uglier ;) templatetypename _Tp _Tp* addressof(_Tp __v) { return reinterpret_cast_Tp* (const_castchar(reinterpret_castconst volatile char(__v))); } It's uglier because the code above doesn't work for functions, and because of compiler bugs. By the way, Peter (I think you are the author of the current boost implementation, which I looked at yesterday), in case we end up having something like the above, temporarily at least, which kind of acknowledgment would you be Ok with? Is it enough your name in the ChangeLog? Any kind of acknowledgment is fine with me, including none at all. Whichever you prefer. :-)
Re: [RFC] Implementing addressof for C++0x
Hi, ... for reference, it would be something like this (in my recollections, it was even uglier ;) templatetypename _Tp _Tp* addressof(_Tp __v) { return reinterpret_cast_Tp* (const_castchar(reinterpret_castconst volatile char(__v))); } It's uglier because the code above doesn't work for functions, Ah, ok, it will be a little bigger then, I missed testing functions, thanks. I will post the complete patch, in case. and because of compiler bugs. Luckily we don't need that. Any kind of acknowledgment is fine with me, including none at all. Whichever you prefer. :-) You are very kind, thanks. After all, we should still be below, say, 20 lines of code, thus, if you are ok with that, we are not going to need a Copyright assignment, etc. Paolo.
Re: [RFC] Implementing addressof for C++0x
On 05/20/2010 01:55 PM, Paolo Carlini wrote: It's uglier because the code above doesn't work for functions, By the way, do you have a specific testcase in mind? Because addressof_fn_test.cpp, part of Boost, passes... Paolo.
Re: [RFC] Implementing addressof for C++0x
Paolo Carlini wrote: On 05/20/2010 02:18 PM, Peter Dimov wrote: On 05/20/2010 01:55 PM, Paolo Carlini wrote: It's uglier because the code above doesn't work for functions, By the way, do you have a specific testcase in mind? Because addressof_fn_test.cpp, part of Boost, passes... This is probably a g++/gcc extension... some compilers do not allow references to functions to be casted to char, and I believe the standard doesn't permit that, either. I see. I'm a bit reluctant to add complexity to the code, given that current Comeau and Intel, at least, in strict-mode, also like it... If it works, there's certainly no need to add complexity. Here's the ticket that prompted the boost::addressof changes: https://svn.boost.org/trac/boost/ticket/1846 but it doesn't say which compiler didn't like it at the time. MSVC 8.0 also does.
Re: [RFC] Implementing addressof for C++0x
Sent from my iPhone On May 20, 2010, at 5:43 AM, Peter Dimov pdi...@pdimov.com wrote: Paolo Carlini wrote: On 05/20/2010 02:18 PM, Peter Dimov wrote: On 05/20/2010 01:55 PM, Paolo Carlini wrote: It's uglier because the code above doesn't work for functions, By the way, do you have a specific testcase in mind? Because addressof_fn_test.cpp, part of Boost, passes... This is probably a g++/gcc extension... some compilers do not allow references to functions to be casted to char, and I believe the standard doesn't permit that, either. I see. I'm a bit reluctant to add complexity to the code, given that current Comeau and Intel, at least, in strict-mode, also like it... If it works, there's certainly no need to add complexity. Here's the ticket that prompted the boost::addressof changes: https://svn.boost.org/trac/boost/ticket/1846 but it doesn't say which compiler didn't like it at the time. MSVC 8.0 also does. I do know at one point gcc changed to reject it by default and then that was reverted as it broke building libjava; not to mention most uses of dlsym. Thanks, Andrew Pinski
Re: [RFC] Implementing addressof for C++0x
On 05/20/2010 08:18 AM, Peter Dimov wrote: On 05/20/2010 01:55 PM, Paolo Carlini wrote: It's uglier because the code above doesn't work for functions, By the way, do you have a specific testcase in mind? Because addressof_fn_test.cpp, part of Boost, passes... This is probably a g++/gcc extension... some compilers do not allow references to functions to be casted to char, and I believe the standard doesn't permit that, either. The standard permits a compiler to accept or reject such a cast. 5.2.10/8: Converting a pointer to a function into a pointer to an object type or vice versa is conditionally-supported. The meaning of such a conversion is implementation-defined, except that if an implementation supports conversions in both directions, converting a prvalue of one type to the other type and back, possibly with different cv-qualification, shall yield the original pointer value. Jason
Re: [RFC] Implementing addressof for C++0x
On 05/20/2010 08:13 PM, Jason Merrill wrote: The standard permits a compiler to accept or reject such a cast. 5.2.10/8: Converting a pointer to a function into a pointer to an object type or vice versa is conditionally-supported. The meaning of such a conversion is implementation-defined, except that if an implementation supports conversions in both directions, converting a prvalue of one type to the other type and back, possibly with different cv-qualification, shall yield the original pointer value. Thanks for the clarification. The library patch which I'll commit later today includes a very simple implementation of std::addressof - essentially what I posted already at the beginning of this thread - and a specific testcase making sure that we can deal correctly with functions: if, for some reason, the compiler changes in the future about this issue, we can immediately notice and adjust std::addressof. Paolo.
Re: [RFC] Implementing addressof for C++0x
Jason Merrill wrote: On 05/20/2010 08:18 AM, Peter Dimov wrote: On 05/20/2010 01:55 PM, Paolo Carlini wrote: It's uglier because the code above doesn't work for functions, By the way, do you have a specific testcase in mind? Because addressof_fn_test.cpp, part of Boost, passes... This is probably a g++/gcc extension... some compilers do not allow references to functions to be casted to char, and I believe the standard doesn't permit that, either. The standard permits a compiler to accept or reject such a cast. 5.2.10/8: Converting a pointer to a function into a pointer to an object type or vice versa is conditionally-supported. Thanks; that is, then, why the latest Comeau accepts it. It didn't occur to me to try the earlier versions on http://www.comeaucomputing.com/tryitout/ - they reject the code. This paragraph is a new addition, not present in C++03; conditionally supported is a C++0x-ism. :-)