[libcxx] r198505 - Switch to using C++ style casts.

Alp Toker alp at nuanti.com
Fri Jan 17 06:33:14 PST 2014


Didn't hear back from you so switched this instance back to the original 
C-style cast for now.

Build fixed, r199494

We'll want to see why clang was accepting this as well.

Alp.


On 11/01/2014 12:08, Alp Toker wrote:
>
> On 04/01/2014 17:43, Joerg Sonnenberger wrote:
>> Modified: libcxx/trunk/src/stdexcept.cpp
>> URL:http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/stdexcept.cpp?rev=198505&r1=198504&r2=198505&view=diff 
>>
>> ============================================================================== 
>>
>> --- libcxx/trunk/src/stdexcept.cpp (original)
>> +++ libcxx/trunk/src/stdexcept.cpp Sat Jan  4 11:43:00 2014
>> @@ -46,7 +46,7 @@ private:
>>       static const std::ptrdiff_t offset = 
>> static_cast<std::ptrdiff_t>(2*sizeof(unused_t) +
>> sizeof(count_t));
>>   -    count_t& count() const_NOEXCEPT {return (count_t&)(*(str_  - 
>> sizeof(count_t)));}
>> +    count_t& count() const_NOEXCEPT {return *const_cast<count_t 
>> *>(reinterpret_cast<const count_t *>(str_  - sizeof(count_t)));}
>>   public:
>>       explicit __libcpp_nmstr(const char* msg);
>>       __libcpp_nmstr(const __libcpp_nmstr& s) _NOEXCEPT;
>> @@ -59,7 +59,7 @@ __libcpp_nmstr::__libcpp_nmstr(const cha
>>   {
>>       std::size_t len = strlen(msg);
>>       str_ = new char[len + 1 + offset];
>> -    unused_t* c = (unused_t*)str_;
>> +    unused_t* c = reinterpret_cast<unused_t*>(const_cast<char 
>> *>(str_));
>>       c[0] = c[1] = len;
>>       str_ += offset;
>>       count() = 0;
>> @@ -79,7 +79,7 @@ __libcpp_nmstr::operator=(const __libcpp
>>       const char* p = str_;
>>       str_ = s.str_;
>>       __sync_add_and_fetch(&count(), 1);
>> -    if (__sync_add_and_fetch((count_t*)(p-sizeof(count_t)), 
>> count_t(-1)) < 0)
>> +    if (__sync_add_and_fetch(reinterpret_cast<const 
>> count_t*>(p-sizeof(count_t)), count_t(-1)) < 0)
>
> Hi Joerg,
>
> The above change doesn't work with g++ (4.8.2).
>
> llvm/projects/libcxx/src/stdexcept.cpp:82:94: error: invalid 
> conversion from ‘const void*’ to ‘volatile void*’ [-fpermissive]
> if (__sync_add_and_fetch(reinterpret_cast<const 
> count_t*>(p-sizeof(count_t)), count_t(-1)) < 0)
>
> Presumably it's because the gcc builtin has a slightly different 
> parameter specification to the one in clang.
>
> Changing this instance back to a C-style cast fixed the LLVM build 
> locally. Should be possible to get it done with C++ casts too.
>
> (This isn't a high priority build configuration for us, but the tree 
> is still meant to be buildable with gcc AFAIK.)
>
> Alp.
>
>
>
>>           delete [] (p-offset);
>>       return *this;
>>   }
>> @@ -102,28 +102,29 @@ namespace std  // purposefully not using
>>     logic_error::logic_error(const string& msg)
>>   {
>> -    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
>> -    ::new(&s) __libcpp_nmstr(msg.c_str());
>> +    __libcpp_nmstr *s = static_cast<__libcpp_nmstr *>(__imp_);
>> +    ::new(s) __libcpp_nmstr(msg.c_str());
>>   }
>>     logic_error::logic_error(const char* msg)
>>   {
>> -    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
>> -    ::new(&s) __libcpp_nmstr(msg);
>> +    __libcpp_nmstr *s = static_cast<__libcpp_nmstr *>(__imp_);
>> +    ::new(s) __libcpp_nmstr(msg);
>>   }
>>     logic_error::logic_error(const logic_error& le) _NOEXCEPT
>>   {
>> -    __libcpp_nmstr& s = (__libcpp_nmstr&)__imp_;
>> -    ::new(&s) __libcpp_nmstr((const __libcpp_nmstr&)le.__imp_);
>> +    __libcpp_nmstr *s = static_cast<__libcpp_nmstr *>(__imp_);
>> +    const __libcpp_nmstr *s2 = static_cast<const __libcpp_nmstr 
>> *>(le.__imp_);
>> +    ::new(s) __libcpp_nmstr(*s2);
>>   }
>

-- 
http://www.nuanti.com
the browser experts




More information about the cfe-commits mailing list