This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] add check cppcoreguidelines-pro-type-const-cast
ClosedPublic

Authored by mgehre on Oct 2 2015, 3:49 PM.

Details

Summary

This check flags all uses of const_cast in C++ code.

Modifying a variable that was declared const is undefined behavior, even
with const_cast.

This rule is part of the "Type safety" profile of the C++ Core
Guidelines, see
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#-type3-dont-use-const_cast-to-cast-away-const-ie-at-all.

Depends on D13313

Diff Detail

Event Timeline

mgehre updated this revision to Diff 36406.Oct 2 2015, 3:49 PM
mgehre retitled this revision from to [clang-tidy] add check cppcoreguidelines-pro-type-const-cast.
mgehre updated this object.
mgehre added a subscriber: cfe-commits.
aaron.ballman accepted this revision.Oct 5 2015, 7:04 AM
aaron.ballman edited edge metadata.

LGTM, despite being bizarrely restrictive guidance.

~Aaron

This revision is now accepted and ready to land.Oct 5 2015, 7:04 AM
mgehre updated this revision to Diff 36668.Oct 6 2015, 2:50 PM
mgehre edited edge metadata.

Rebased

alexfh edited edge metadata.Oct 6 2015, 8:07 PM

It looks like potentially we're going to have tens of checks in this module. I wonder whether we should start organizing the checks somehow right away. For example, create a directory (and a namespace) for each profile. We'd need to adapt the add_new_check.py script to support this then.

Just a thought. The patch LG.

aaron.ballman closed this revision.Oct 7 2015, 5:27 AM

Thanks for the patch! I've commit in r249540.

Given the number of checkers that you're working on, I would recommend getting commit privileges if you'd like them.