[PATCH] D21992: [clang-tidy] new cppcoreguidelines-slicing

Clement Courbet via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 11 01:55:26 PDT 2016


courbet added a comment.

I've ran this check on llvm. There are 0 instances of virtual function slicing (which is not surprising since these usually result in actual bugs) and 71 instances of member varaible slicing:

- 'FullSourceLoc' to 'SourceLocation': 57
- 'APSInt' to 'APInt': 5
- 'DeducedTemplateArgument' to 'TemplateArgument': 3
- 'SemaDiagnosticBuilder' to 'DiagnosticBuilder': 2
- 'RegHalf' to 'RegisterRef': 2
- 'PathDiagnosticRange' to 'SourceRange': 2

Most are harmless (but still true positives). The 'SemaDiagnosticBuilder' and 'APSInt' are actually interesting:

llvm/llvm/tools/clang/lib/Sema/SemaExprObjC.cpp:3555
``DiagnosticBuilder DiagB = …`` should be: ``SemaDiagnosticBuilder DiagB = …``
DiagB is then passed by reference to a function, so there really is no reason to slice it.

AST/ExprConstant.cpp:3150
``explicit APSInt(APInt I, bool isUnsigned = true)``
Here it’s easy to write: ``APSInt MyInt(MyOtherInt);`` and think it’s a copy, but it’s not (it just changed the signedness). ``APSInt MyInt(MyOtherInt.toAPInt());`` would make it clear what’s happening.


http://reviews.llvm.org/D21992





More information about the cfe-commits mailing list