summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp2
-rw-r--r--clang-tools-extra/test/clang-tidy/google-readability-casting.c2
-rw-r--r--clang-tools-extra/test/clang-tidy/google-readability-casting.cpp11
3 files changed, 12 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index ae9c74e8b3d..b3caf917520 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -149,7 +149,7 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
ReplaceWithNamedCast("static_cast");
return;
case CK_ConstructorConversion:
- if (!DestTypeAsWritten.hasQualifiers() &&
+ if (!CastExpr->getTypeAsWritten().hasQualifiers() &&
DestTypeAsWritten->isRecordType() &&
!DestTypeAsWritten->isElaboratedTypeSpecifier()) {
Diag << "constructor call syntax";
diff --git a/clang-tools-extra/test/clang-tidy/google-readability-casting.c b/clang-tools-extra/test/clang-tidy/google-readability-casting.c
index df167454316..488bcd79637 100644
--- a/clang-tools-extra/test/clang-tidy/google-readability-casting.c
+++ b/clang-tools-extra/test/clang-tidy/google-readability-casting.c
@@ -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-FIXES: const char *cpc2 = cpc;
char *pc = (char*)cpc;
+ typedef const char *Typedef1;
+ (Typedef1)cpc;
}
#endif
diff --git a/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp b/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
index e150c710735..a4d29d6b28f 100644
--- a/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/google-readability-casting.cpp
@@ -81,6 +81,9 @@ void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
int b1 = (int)b;
// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: {{.*}}; use static_cast [
// 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;
// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: {{.*}}; use static_cast/const_cast/reinterpret_cast [
@@ -271,11 +274,15 @@ void conversions() {
auto s2a = (struct S)"";
// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged; use static_cast [
// 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;
auto s3 = (const S&)c;
// 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;
- // FIXME: This should be a static_cast
+ // FIXME: This should be a static_cast.
// C HECK-FIXES: auto s3 = static_cast<const S&>(c);
auto s4 = (S)c;
// 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;
// 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;
- // FIXME: This should be a static_cast
+ // FIXME: This should be a static_cast.
// C HECK-FIXES: auto s5 = static_cast<const S&>(cr);
auto s6 = (S)cr;
// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged; use constructor call syntax [
OpenPOWER on IntegriCloud