Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Add checker to re-write c-style casts into a sequence of c++-style casts #26295

Open Quuxplusone opened 8 years ago

Quuxplusone commented 8 years ago
Bugzilla Link PR26296
Status NEW
Importance P enhancement
Reported by Jon Roelofs (jroelofs@jroelofs.com)
Reported on 2016-01-25 14:27:26 -0800
Last modified on 2016-02-03 14:07:15 -0800
Version unspecified
Hardware PC All
CC aaron@aaronballman.com, alexfh@google.com, djasper@google.com, jroelofs@jroelofs.com, klimek@google.com, legalize@xmission.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
It would be neat to have a checker+fixit that replaces this:

  const char *c = ...;
  void *v = (void*)c;

with this:

  const char *c = ...;
  void *v = static_cast<void*>(const_cast<char *>(c));
Quuxplusone commented 8 years ago

I don't think we need another cast-related check, since we have several of those. For example, there's google-readability-casting, which already provides fixes in some cases. Feel free to add support for generating chains of named casts for more complex cases. Maybe we should even join all c-style-cast-related checks to one check with a number of options.

Quuxplusone commented 8 years ago
In the example provided, the cast to void * is redundant, whether done by C-
style cast or static_cast<>.

Every pointer type is implicitly convertible to pointer to void.

The converse is not true.

See section 4.10 Pointer converions [conv.ptr] in the C++ standard.
Quuxplusone commented 8 years ago
> In the example provided, the cast to void * is redundant, whether done by C-
style cast or static_cast<>.

Oops, right... got it backwards.