[result_of] BOOST_RESULT_OF_USE_DECLTYPE in a C++03 mode with libc++

This is just a small note related to boost::result_of. When BOOST_RESULT_OF_USE_DECLTYPE is defined, boost::result_of tries to use decltype-based implementation (regardless of the compiler's decltype support). Surprisingly, in a C++03 mode, libc++ defines `decltype` using `__typeof__`: Bug 12488 (WONTFIX): decltype can be used in C++03 with no errors, no warnings http://llvm.org/bugs/show_bug.cgi?id=12488 So, when used with libc++, boost::result_of can be used with BOOST_RESULT_OF_USE_DECLTYPE even in a C++03 mode. Regards, Michel

On 10/8/2012 6:08 AM, Michel Morin wrote:
This is just a small note related to boost::result_of.
When BOOST_RESULT_OF_USE_DECLTYPE is defined, boost::result_of tries to use decltype-based implementation (regardless of the compiler's decltype support).
Surprisingly, in a C++03 mode, libc++ defines `decltype` using `__typeof__`:
Bug 12488 (WONTFIX): decltype can be used in C++03 with no errors, no warnings http://llvm.org/bugs/show_bug.cgi?id=12488
So, when used with libc++, boost::result_of can be used with BOOST_RESULT_OF_USE_DECLTYPE even in a C++03 mode.
Does __typeof__ have EXACTLY the same semantics as C++11 decltype? Can it get you either the type and lvalue-ness of an expression, or the variable's declared type, with an extra set of parens? If the expression is a function call, does it force the return type to be complete? We're finding very few compilers have robust-enough implementations of decltype to flip the result_of switch. I think it's pretty improbable that a pre-standard hack like __typeof__ would fit the bill. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric Niebler wrote:
On 10/8/2012 6:08 AM, Michel Morin wrote:
This is just a small note related to boost::result_of.
When BOOST_RESULT_OF_USE_DECLTYPE is defined, boost::result_of tries to use decltype-based implementation (regardless of the compiler's decltype support).
Surprisingly, in a C++03 mode, libc++ defines `decltype` using `__typeof__`:
Bug 12488 (WONTFIX): decltype can be used in C++03 with no errors, no warnings http://llvm.org/bugs/show_bug.cgi?id=12488
So, when used with libc++, boost::result_of can be used with BOOST_RESULT_OF_USE_DECLTYPE even in a C++03 mode.
Does __typeof__ have EXACTLY the same semantics as C++11 decltype?
No, it doesn't. I don't like the idea of defining `decltype` macro in libc++: #ifdef _LIBCPP_HAS_NO_DECLTYPE #define decltype(x) __typeof__(x) #endif I created the bug report to libc++, but it got WONTFIX. Regards, Michel

On 10/8/2012 9:59 AM, Michel Morin wrote:
Eric Niebler wrote:
On 10/8/2012 6:08 AM, Michel Morin wrote:
This is just a small note related to boost::result_of.
When BOOST_RESULT_OF_USE_DECLTYPE is defined, boost::result_of tries to use decltype-based implementation (regardless of the compiler's decltype support).
Surprisingly, in a C++03 mode, libc++ defines `decltype` using `__typeof__`:
Bug 12488 (WONTFIX): decltype can be used in C++03 with no errors, no warnings http://llvm.org/bugs/show_bug.cgi?id=12488
So, when used with libc++, boost::result_of can be used with BOOST_RESULT_OF_USE_DECLTYPE even in a C++03 mode.
Does __typeof__ have EXACTLY the same semantics as C++11 decltype?
No, it doesn't. I don't like the idea of defining `decltype` macro in libc++:
#ifdef _LIBCPP_HAS_NO_DECLTYPE #define decltype(x) __typeof__(x) #endif
I created the bug report to libc++, but it got WONTFIX.
Oh, I get it now. That's not good. I've added my $0.02 to the bug report. Thanks for making me aware of this. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
Eric Niebler
-
Michel Morin