[PATCH] D14096: [clang-tidy] add new check cppcoreguidelines-pro-type-cstyle-cast

Joerg Sonnenberger via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 2 01:43:05 PST 2015


On Sun, Nov 01, 2015 at 08:48:53PM -0500, Aaron Ballman via cfe-commits wrote:
> On Sun, Nov 1, 2015 at 2:31 PM, Joerg Sonnenberger via cfe-commits
> <cfe-commits at lists.llvm.org> wrote:
> > On Tue, Oct 27, 2015 at 06:10:26PM +0000, Samuel Benzaquen via cfe-commits wrote:
> >> sbenza added a comment.
> >>
> >> In http://reviews.llvm.org/D14096#275902, @xazax.hun wrote:
> >>
> >> > There is already a similar check in the Google package. What are the differences between those two checks? What is the reason we can not just register that check into the core guidelines module?
> >>
> >>
> >> That other check discourages c-style cast in favor of C++ style casts, even if it is a reinterpret_cast. It simply replaces the cstyle cast with an equivalent C++ one. It is basically a stylistic check.
> >>
> >> This check will warn unsafe cstyle casts, while allowing safe ones like int->uint casts.
> >> This one is a safety related check.
> >
> > Looking back to the discussion about the C++ style casts, this argument
> > makes no sense. For C++ code, reinterpret_cast is clearly preferable
> > over C-style casts for all but code size reasons. There seems to be no
> > consideration about "safe" uses with reinterpret_cast, so why should C-style casts
> > be different?
> 
> "Clearly preferable" is kind of debatable, but I don't disagree with
> your statement. That being said, this checker isn't concerned with
> C++-style casts, so I'm not certain I understand what you would like
> to see changed with this checker. Can you elaborate?

Let me reverse that. Do the core guidelines really define a set of
"safe" C-style casts and don't have the equivalent for C++ casts? The
latter is what I took from the follow-up on the introduction of the C++
cast checkers.

Joerg


More information about the cfe-commits mailing list