[PATCH] D151187: [doc] Add casting style preference to coding standards
Sergei Barannikov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 23 04:56:31 PDT 2023
barannikov88 added a comment.
In D151187#4363988 <https://reviews.llvm.org/D151187#4363988>, @jhenderson wrote:
> In D151187#4363915 <https://reviews.llvm.org/D151187#4363915>, @barannikov88 wrote:
>
>> What about function style casts? I personally find them acceptable in limited cases, such as "constructing" int64_t from unsigned.
>
> It's a fair question, and I don't have a good answer for this. Strictly, we should //probably// forbid them in new code on the basis that they are just as bad as C-style casts (they are explicitly defined to be identical), with regards to safety etc, but I also have used them in the past for the same "constructing" style like you find. Any suggestion on how we might codify the latter.
Maybe adopt this clang-tidy check? https://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/pro-type-cstyle-cast.html
That is, allow C/functional-style cast when it is known to be safe (like unsigned -> int64_t or enum -> int), and prefer named casts otherwise.
The check also provides fix-its, which is nice.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D151187/new/
https://reviews.llvm.org/D151187
More information about the llvm-commits
mailing list