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

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 2 16:01:53 PST 2015


On Mon, Nov 2, 2015 at 4:43 AM, Joerg Sonnenberger via cfe-commits
<cfe-commits at lists.llvm.org> wrote:
> 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.

Okay, that makes more sense to me -- thank you for the clarification.

My understanding is that the core guidelines define a set of "safe"
C-style casts and don't have the equivalent for C++ casts. That seems
like a good bug report to file with the core guidelines folks
(https://github.com/isocpp/CppCoreGuidelines/issues). I agree that it
seems strange that a C-style cast resulting in reinterpret_cast is
safe and not diagnosed, while the same effective cast spelled with
reinterpret_cast is diagnosed.

~Aaron

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


More information about the cfe-commits mailing list