[clang-tools-extra] r296858 - [clang-tidy] google-readability-casting: don't use constructor call syntax for const types
Alexander Kornienko via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 3 00:18:49 PST 2017
Author: alexfh
Date: Fri Mar 3 02:18:49 2017
New Revision: 296858
URL: http://llvm.org/viewvc/llvm-project?rev=296858&view=rev
Log:
[clang-tidy] google-readability-casting: don't use constructor call syntax for const types
Modified:
clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c
clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp
Modified: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp?rev=296858&r1=296857&r2=296858&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp Fri Mar 3 02:18:49 2017
@@ -149,7 +149,7 @@ void AvoidCStyleCastsCheck::check(const
ReplaceWithNamedCast("static_cast");
return;
case CK_ConstructorConversion:
- if (!DestTypeAsWritten.hasQualifiers() &&
+ if (!CastExpr->getTypeAsWritten().hasQualifiers() &&
DestTypeAsWritten->isRecordType() &&
!DestTypeAsWritten->isElaboratedTypeSpecifier()) {
Diag << "constructor call syntax";
Modified: clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c?rev=296858&r1=296857&r2=296858&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.c Fri Mar 3 02:18:49 2017
@@ -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
Modified: clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp?rev=296858&r1=296857&r2=296858&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/google-readability-casting.cpp Fri Mar 3 02:18:49 2017
@@ -81,6 +81,9 @@ void f(int a, double b, const char *cpc,
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 [
More information about the cfe-commits
mailing list