forked from OSchip/llvm-project
[clang-tidy] google-readability-casting: detect redundant casts with top-level const
llvm-svn: 296755
This commit is contained in:
parent
e80d6d1360
commit
b7f6fe4658
|
@ -75,12 +75,12 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
|
|||
T->isMemberFunctionPointerType();
|
||||
};
|
||||
|
||||
const QualType DestTypeAsWritten = CastExpr->getTypeAsWritten();
|
||||
const QualType SourceTypeAsWritten = CastExpr->getSubExprAsWritten()->getType();
|
||||
const QualType SourceType =
|
||||
SourceTypeAsWritten.getCanonicalType().getUnqualifiedType();
|
||||
const QualType DestType =
|
||||
DestTypeAsWritten.getCanonicalType().getUnqualifiedType();
|
||||
const QualType DestTypeAsWritten =
|
||||
CastExpr->getTypeAsWritten().getUnqualifiedType();
|
||||
const QualType SourceTypeAsWritten =
|
||||
CastExpr->getSubExprAsWritten()->getType().getUnqualifiedType();
|
||||
const QualType SourceType = SourceTypeAsWritten.getCanonicalType();
|
||||
const QualType DestType = DestTypeAsWritten.getCanonicalType();
|
||||
|
||||
bool FnToFnCast =
|
||||
isFunction(SourceTypeAsWritten) && isFunction(DestTypeAsWritten);
|
||||
|
|
|
@ -103,6 +103,19 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
|
|||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}}; use static_cast [
|
||||
// CHECK-FIXES: Enum e = static_cast<Enum>(b1);
|
||||
|
||||
e = (Enum)Enum1;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
|
||||
// CHECK-FIXES: {{^}} e = Enum1;
|
||||
|
||||
e = (Enum)e;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: redundant cast to the same type
|
||||
// CHECK-FIXES: {{^}} e = e;
|
||||
|
||||
static const int kZero = 0;
|
||||
(int)kZero;
|
||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: redundant cast to the same type
|
||||
// CHECK-FIXES: {{^}} kZero;
|
||||
|
||||
int b2 = int(b);
|
||||
int b3 = static_cast<double>(b);
|
||||
int b4 = b;
|
||||
|
|
Loading…
Reference in New Issue