forked from OSchip/llvm-project
[clang-tidy] google-readability-casting: don't use constructor call syntax for const types
llvm-svn: 296858
This commit is contained in:
parent
69bccf96bd
commit
db04cccb87
|
@ -149,7 +149,7 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
|
||||||
ReplaceWithNamedCast("static_cast");
|
ReplaceWithNamedCast("static_cast");
|
||||||
return;
|
return;
|
||||||
case CK_ConstructorConversion:
|
case CK_ConstructorConversion:
|
||||||
if (!DestTypeAsWritten.hasQualifiers() &&
|
if (!CastExpr->getTypeAsWritten().hasQualifiers() &&
|
||||||
DestTypeAsWritten->isRecordType() &&
|
DestTypeAsWritten->isRecordType() &&
|
||||||
!DestTypeAsWritten->isElaboratedTypeSpecifier()) {
|
!DestTypeAsWritten->isElaboratedTypeSpecifier()) {
|
||||||
Diag << "constructor call syntax";
|
Diag << "constructor call syntax";
|
||||||
|
|
|
@ -17,6 +17,8 @@ void f(const char *cpc) {
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
|
// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
|
||||||
// CHECK-FIXES: const char *cpc2 = cpc;
|
// CHECK-FIXES: const char *cpc2 = cpc;
|
||||||
char *pc = (char*)cpc;
|
char *pc = (char*)cpc;
|
||||||
|
typedef const char *Typedef1;
|
||||||
|
(Typedef1)cpc;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -81,6 +81,9 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
|
||||||
int b1 = (int)b;
|
int b1 = (int)b;
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}}; use static_cast [
|
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}}; use static_cast [
|
||||||
// CHECK-FIXES: int b1 = static_cast<int>(b);
|
// CHECK-FIXES: int b1 = static_cast<int>(b);
|
||||||
|
b1 = (const int&)b;
|
||||||
|
// CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
|
||||||
|
// CHECK-FIXES: b1 = (const int&)b;
|
||||||
|
|
||||||
Y *pB = (Y*)pX;
|
Y *pB = (Y*)pX;
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
|
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
|
||||||
|
@ -271,11 +274,15 @@ void conversions() {
|
||||||
auto s2a = (struct S)"";
|
auto s2a = (struct S)"";
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use static_cast [
|
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use static_cast [
|
||||||
// CHECK-FIXES: auto s2a = static_cast<struct S>("");
|
// CHECK-FIXES: auto s2a = static_cast<struct S>("");
|
||||||
|
auto s2b = (const S)"";
|
||||||
|
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use static_cast [
|
||||||
|
// FIXME: This should be constructor call syntax: S("").
|
||||||
|
// CHECK-FIXES: auto s2b = static_cast<const S>("");
|
||||||
ConvertibleToS c;
|
ConvertibleToS c;
|
||||||
auto s3 = (const S&)c;
|
auto s3 = (const S&)c;
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [
|
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [
|
||||||
// CHECK-FIXES: auto s3 = (const S&)c;
|
// CHECK-FIXES: auto s3 = (const S&)c;
|
||||||
// FIXME: This should be a static_cast
|
// FIXME: This should be a static_cast.
|
||||||
// C HECK-FIXES: auto s3 = static_cast<const S&>(c);
|
// C HECK-FIXES: auto s3 = static_cast<const S&>(c);
|
||||||
auto s4 = (S)c;
|
auto s4 = (S)c;
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
|
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
|
||||||
|
@ -284,7 +291,7 @@ void conversions() {
|
||||||
auto s5 = (const S&)cr;
|
auto s5 = (const S&)cr;
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [
|
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use static_cast/const_cast/reinterpret_cast [
|
||||||
// CHECK-FIXES: auto s5 = (const S&)cr;
|
// CHECK-FIXES: auto s5 = (const S&)cr;
|
||||||
// FIXME: This should be a static_cast
|
// FIXME: This should be a static_cast.
|
||||||
// C HECK-FIXES: auto s5 = static_cast<const S&>(cr);
|
// C HECK-FIXES: auto s5 = static_cast<const S&>(cr);
|
||||||
auto s6 = (S)cr;
|
auto s6 = (S)cr;
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
|
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
|
||||||
|
|
Loading…
Reference in New Issue