rjmccall added a comment.

In https://reviews.llvm.org/D33826#856652, @lebedev.ri wrote:

> In https://reviews.llvm.org/D33826#856619, @Eugene.Zelenko wrote:
>
> > In https://reviews.llvm.org/D33826#856610, @lebedev.ri wrote:
> >
> > > Any status update here? :)
> > >  I generally do see a benefit in this check, because `-Wcast-align` (at 
> > > least currently?) does not warn on `reinterpret_cast<>()`.
> >
> >
> > I think will be good idea to extend -Wcast-align.
>
>
> Hm, are you *sure* `reinterpret_cast<>()` is not allowed to increase 
> alignment?
>  There was a commit that intentionally removed that warning: (by @rjmccall, i 
> believe)
>  
> https://github.com/llvm-mirror/clang/commit/35a38d95da89d48778019c37b5f8c9a20f7e309c


One of the fundamental design principles to keep in mind when implementing 
warnings like -Wcast-align is that we're trying to warn users about having 
written something dangerous, not scold them for writing code a particular way.  
Users do need to do these casts sometimes, and there has to be some way of 
doing them without a warning.  So the question of when to warn has to consider 
whether the code is explicitly acknowledging the danger.  It would, for 
example, be a mistake to warn in C about double-casts through (void*), because 
that is not something that people do accidentally; it is very likely that it is 
an attempt to suppress the warning.  In C++, it seemed to me that a 
reinterpret_cast is by its nature explicitly acknowledging the danger, so it is 
never really appropriate to warn.


Repository:
  rL LLVM

https://reviews.llvm.org/D33826



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to