[cfe-commits] r148874 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/Analysis/reference.cpp

Matthieu Monrocq matthieu.monrocq at gmail.com
Sun Jan 29 04:40:35 PST 2012


Le 29 janvier 2012 09:30, Chandler Carruth <chandlerc at google.com> a écrit :

> FWIW, I've not checked to see whether it could just be replaced with
> abort, or no body at all. I'll look into it when I can. However...
>
> On Sat, Jan 28, 2012 at 10:38 PM, Nico Weber <thakis at chromium.org> wrote:
>
>> You mean like
>>
>> template <typename T>
>> inline T Invalid() {
>>   return *static_cast<volatile typename remove_reference<T>::type*>(0);
>>
>
> The error below can be addressed quite simply:
>
> return *const_cast<typename
> remove_reference<T>::type&>(static_cast<volatile typename
> remove_reference<T>::type*>(0));
>
> You might think that this could just be 'const_cast<T&>(...)' but while
> this is equivalent according to the standard thanks to reference
> collapsing, we found that some compilers choked on it spectacularly. =/ I
> can't remember whether it was an older MSVC, or the GCC in an older version
> of xcode.
>
>
>
// the reference looks wrong
return *const_cast<typename
remove_reference<T>::type&>(static_cast<volatile typename
remove_reference<T>::type*>(0));

// this looks better
return *const_cast<typename
remove_reference<T>::type*>(static_cast<volatile typename
remove_reference<T>::type*>(0));

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120129/74fc4ed4/attachment.html>


More information about the cfe-commits mailing list