[PATCH] [libcxx] Use __decltype instead of __typeof__

Eric Fiselier eric at efcs.ca
Sun Jun 14 13:08:12 PDT 2015

In http://reviews.llvm.org/D10426#187768, @majnemer wrote:

> Is there a concrete benefit that this provides?

It makes the `#define decltype` actually provide correct `decltype` semantics in C++03. Since clang and GCC don't provide `decltype` in C++03 we used to fall back on `__typeof__`.  Because `__typeof__` does not deduce references it would change the meaning of code between C++03 and C++11. I think this change is beneficial to libc++ users who use the `decltype` macro we provide in C++03.

A concrete example within libc++ is the C++03 implementations of `__invoke` and `result_of` used to use `__typeof__` to deduce the return type of a call to a function object. If the return type was a reference we would get it wrong and `__invoke` will end up returning by value.

PS. I don't like that libc++ provides `decltype` to users in C++03 but I think it's way to late to change that.



More information about the cfe-commits mailing list