[PATCH] Suggest automated replacements of C-style casts with C++ casts.
Daniel Jasper
djasper at google.com
Sat Jul 12 04:23:24 PDT 2014
================
Comment at: clang-tidy/google/AvoidCStyleCastsCheck.cpp:33
@@ -30,1 +32,3 @@
+bool needConstCast(QualType SourceType, QualType DestType) {
+ SourceType = SourceType.getNonReferenceType();
----------------
nit: Grammatically, I'd prefer "needsConstCast"
================
Comment at: clang-tidy/google/AvoidCStyleCastsCheck.cpp:70
@@ +69,3 @@
+
+ auto ParenRange = CharSourceRange::getTokenRange(CastExpr->getLParenLoc(),
+ CastExpr->getRParenLoc());
----------------
Create a test where the cast is inside a macro. I think you'll want to use the spelling location (or completely abort as the required cast type might actually be different between different macro invocations).
================
Comment at: clang-tidy/google/AvoidCStyleCastsCheck.cpp:120
@@ +119,3 @@
+ return;
+ }
+ default:
----------------
Though benign now, don't fall through here.
================
Comment at: test/clang-tidy/avoid-c-style-casts.cpp:9
@@ +8,3 @@
+
+void f(int a, double b, const char *cpc, const void *cpv, X *pX) {
+ const char *cpc2 = (const char*)cpc;
----------------
What happens for the following code?
template <typename T> void f(T t) { int i = (int)t; }
f(1);
f(1.0);
(With the first call to f() hopefully leading to a message about a redundant cast and the second call leading to a reinterpret_cast)
http://reviews.llvm.org/D4478
More information about the cfe-commits
mailing list