@@ -29,15 +29,15 @@ AST_MATCHER_P(QualType, hasAnyType, std::vector<StringRef>, Names) {
2929 if (Names.empty ())
3030 return false ;
3131
32- std::string Name = Node.getLocalUnqualifiedType ().getAsString ();
32+ const std::string Name = Node.getLocalUnqualifiedType ().getAsString ();
3333 return llvm::is_contained (Names, Name);
3434}
3535
3636AST_MATCHER (FieldDecl, hasIntBitwidth) {
3737 assert (Node.isBitField ());
3838 const ASTContext &Ctx = Node.getASTContext ();
39- unsigned IntBitWidth = Ctx.getIntWidth (Ctx.IntTy );
40- unsigned CurrentBitWidth = Node.getBitWidthValue ();
39+ const unsigned IntBitWidth = Ctx.getIntWidth (Ctx.IntTy );
40+ const unsigned CurrentBitWidth = Node.getBitWidthValue ();
4141 return IntBitWidth == CurrentBitWidth;
4242}
4343
@@ -79,7 +79,7 @@ void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
7979 const auto IsCeilFloorCallExpr = expr (callExpr (callee (functionDecl (
8080 hasAnyName (" ::ceil" , " ::std::ceil" , " ::floor" , " ::std::floor" )))));
8181
82- std::vector<StringRef> IgnoreConversionFromTypesVec =
82+ const std::vector<StringRef> IgnoreConversionFromTypesVec =
8383 utils::options::parseStringList (IgnoreConversionFromTypes);
8484
8585 // We may want to exclude other types from the checks, such as `size_type`
@@ -243,7 +243,7 @@ struct IntegerRange {
243243static IntegerRange createFromType (const ASTContext &Context,
244244 const BuiltinType &T) {
245245 if (T.isFloatingPoint ()) {
246- unsigned PrecisionBits = llvm::APFloatBase::semanticsPrecision (
246+ const unsigned PrecisionBits = llvm::APFloatBase::semanticsPrecision (
247247 Context.getFloatTypeSemantics (T.desugar ()));
248248 // Contrary to two's complement integer, floating point values are
249249 // symmetric and have the same number of positive and negative values.
@@ -262,24 +262,24 @@ static IntegerRange createFromType(const ASTContext &Context,
262262 return {LowerValue, UpperValue};
263263 }
264264 assert (T.isInteger () && " Unexpected builtin type" );
265- uint64_t TypeSize = Context.getTypeSize (&T);
266- bool IsUnsignedInteger = T.isUnsignedInteger ();
265+ const uint64_t TypeSize = Context.getTypeSize (&T);
266+ const bool IsUnsignedInteger = T.isUnsignedInteger ();
267267 return {llvm::APSInt::getMinValue (TypeSize, IsUnsignedInteger),
268268 llvm::APSInt::getMaxValue (TypeSize, IsUnsignedInteger)};
269269}
270270
271271static bool isWideEnoughToHold (const ASTContext &Context,
272272 const BuiltinType &FromType,
273273 const BuiltinType &ToType) {
274- IntegerRange FromIntegerRange = createFromType (Context, FromType);
275- IntegerRange ToIntegerRange = createFromType (Context, ToType);
274+ const IntegerRange FromIntegerRange = createFromType (Context, FromType);
275+ const IntegerRange ToIntegerRange = createFromType (Context, ToType);
276276 return ToIntegerRange.contains (FromIntegerRange);
277277}
278278
279279static bool isWideEnoughToHold (const ASTContext &Context,
280280 const llvm::APSInt &IntegerConstant,
281281 const BuiltinType &ToType) {
282- IntegerRange ToIntegerRange = createFromType (Context, ToType);
282+ const IntegerRange ToIntegerRange = createFromType (Context, ToType);
283283 return ToIntegerRange.contains (IntegerConstant);
284284}
285285
@@ -289,13 +289,13 @@ static bool isWideEnoughToHold(const ASTContext &Context,
289289static bool isFloatExactlyRepresentable (const ASTContext &Context,
290290 const llvm::APFloat &FloatConstant,
291291 const QualType &DestType) {
292- unsigned DestWidth = Context.getIntWidth (DestType);
293- bool DestSigned = DestType->isSignedIntegerOrEnumerationType ();
292+ const unsigned DestWidth = Context.getIntWidth (DestType);
293+ const bool DestSigned = DestType->isSignedIntegerOrEnumerationType ();
294294 llvm::APSInt Result = llvm::APSInt (DestWidth, !DestSigned);
295295 bool IsExact = false ;
296- bool Overflows = FloatConstant.convertToInteger (
297- Result, llvm::APFloat::rmTowardZero, &IsExact) &
298- llvm::APFloat::opInvalidOp;
296+ const bool Overflows = FloatConstant.convertToInteger (
297+ Result, llvm::APFloat::rmTowardZero, &IsExact) &
298+ llvm::APFloat::opInvalidOp;
299299 return !Overflows && IsExact;
300300}
301301
@@ -321,8 +321,8 @@ bool NarrowingConversionsCheck::isWarningInhibitedByEquivalentSize(
321321 // With this option, we don't warn on conversions that have equivalent width
322322 // in bits. eg. uint32 <-> int32.
323323 if (!WarnOnEquivalentBitWidth) {
324- uint64_t FromTypeSize = Context.getTypeSize (&FromType);
325- uint64_t ToTypeSize = Context.getTypeSize (&ToType);
324+ const uint64_t FromTypeSize = Context.getTypeSize (&FromType);
325+ const uint64_t ToTypeSize = Context.getTypeSize (&ToType);
326326 if (FromTypeSize == ToTypeSize) {
327327 return true ;
328328 }
@@ -406,8 +406,8 @@ void NarrowingConversionsCheck::handleIntegralCast(const ASTContext &Context,
406406 // With this option, we don't warn on conversions that have equivalent width
407407 // in bits. eg. uint32 <-> int32.
408408 if (!WarnOnEquivalentBitWidth) {
409- uint64_t FromTypeSize = Context.getTypeSize (FromType);
410- uint64_t ToTypeSize = Context.getTypeSize (ToType);
409+ const uint64_t FromTypeSize = Context.getTypeSize (FromType);
410+ const uint64_t ToTypeSize = Context.getTypeSize (ToType);
411411 if (FromTypeSize == ToTypeSize)
412412 return ;
413413 }
@@ -583,7 +583,7 @@ void NarrowingConversionsCheck::handleImplicitCast(
583583 return ;
584584 if (handleConditionalOperator (Context, Lhs, Rhs))
585585 return ;
586- SourceLocation SourceLoc = Lhs.getExprLoc ();
586+ const SourceLocation SourceLoc = Lhs.getExprLoc ();
587587 switch (Cast.getCastKind ()) {
588588 case CK_BooleanToSignedIntegral:
589589 handleBooleanToSignedIntegral (Context, SourceLoc, Lhs, Rhs);
0 commit comments