[clang-tools-extra] r285601 - Add modernize-use-auto tests for casts inside macros

Malcolm Parsons via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 10:17:45 PDT 2016


Author: malcolm.parsons
Date: Mon Oct 31 12:17:45 2016
New Revision: 285601

URL: http://llvm.org/viewvc/llvm-project?rev=285601&view=rev
Log:
Add modernize-use-auto tests for casts inside macros

Modified:
    clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
    clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp?rev=285601&r1=285600&r2=285601&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp Mon Oct 31 12:17:45 2016
@@ -96,6 +96,17 @@ void f_const_cast() {
   // CHECK-FIXES: auto  &a3 = const_cast<A &>(*a1);
 }
 
+typedef unsigned char xmlChar;
+#define BAD_CAST (xmlChar *)
+
+#define XMLCHAR_CAST(x) (xmlChar *)(x)
+
+#define CAST_IN_MACRO(x)         \
+  do {                           \
+    xmlChar *s = (xmlChar *)(x); \
+  } while (false);
+// CHECK-FIXES: xmlChar *s = (xmlChar *)(x);
+
 void f_cstyle_cast() {
   auto *a = new A();
   C *c1 = (C *)a;
@@ -105,6 +116,15 @@ void f_cstyle_cast() {
   C &c2 = (C &)*a;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
   // CHECK-FIXES: auto  &c2 = (C &)*a;
+
+  xmlChar  *s = BAD_CAST "xml";
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto s = BAD_CAST "xml";
+  xmlChar  *t = XMLCHAR_CAST("xml");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto t = XMLCHAR_CAST("xml");
+  CAST_IN_MACRO("xml");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
 }
 
 void f_functional_cast() {

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp?rev=285601&r1=285600&r2=285601&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp Mon Oct 31 12:17:45 2016
@@ -98,6 +98,17 @@ void f_const_cast() {
   // CHECK-FIXES: auto &a3 = const_cast<A &>(*a1);
 }
 
+typedef unsigned char xmlChar;
+#define BAD_CAST (xmlChar *)
+
+#define XMLCHAR_CAST(x) (xmlChar *)(x)
+
+#define CAST_IN_MACRO(x)         \
+  do {                           \
+    xmlChar *s = (xmlChar *)(x); \
+  } while (false);
+// CHECK-FIXES: xmlChar *s = (xmlChar *)(x);
+
 void f_cstyle_cast() {
   auto *a = new A();
   C *c1 = (C *)a;
@@ -107,6 +118,15 @@ void f_cstyle_cast() {
   C &c2 = (C &)*a;
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
   // CHECK-FIXES: auto &c2 = (C &)*a;
+
+  xmlChar *s = BAD_CAST "xml";
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *s = BAD_CAST "xml";
+  xmlChar *t = XMLCHAR_CAST("xml");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *t = XMLCHAR_CAST("xml");
+  CAST_IN_MACRO("xml");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
 }
 
 void f_functional_cast() {




More information about the cfe-commits mailing list