From 2192a8e5193716613bb9d64090a8843f7e5ca7fb Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Sun, 26 Oct 2014 01:41:14 +0000 Subject: [clang-tidy] Bring order to check registration. Summary: Register readability checks in a separate module. Renamed the checks and test file names accordingly. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D5936 llvm-svn: 220631 --- .../test/clang-tidy/avoid-c-style-casts.cpp | 126 --------------------- 1 file changed, 126 deletions(-) delete mode 100644 clang-tools-extra/test/clang-tidy/avoid-c-style-casts.cpp (limited to 'clang-tools-extra/test/clang-tidy/avoid-c-style-casts.cpp') diff --git a/clang-tools-extra/test/clang-tidy/avoid-c-style-casts.cpp b/clang-tools-extra/test/clang-tidy/avoid-c-style-casts.cpp deleted file mode 100644 index 414fa8bbcab..00000000000 --- a/clang-tools-extra/test/clang-tidy/avoid-c-style-casts.cpp +++ /dev/null @@ -1,126 +0,0 @@ -// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s google-readability-casting %t -// REQUIRES: shell - -bool g() { return false; } - -enum Enum { Enum1 }; -struct X {}; -struct Y : public X {}; - -void f(int a, double b, const char *cpc, const void *cpv, X *pX) { - const char *cpc2 = (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; - // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char *pc = const_cast(cpc); - - char *pc2 = (char*)(cpc + 33); - // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char *pc2 = const_cast(cpc + 33); - - const char &crc = *cpc; - char &rc = (char&)crc; - // CHECK-MESSAGES: :[[@LINE-1]]:14: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char &rc = const_cast(crc); - - char &rc2 = (char&)*cpc; - // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char &rc2 = const_cast(*cpc); - - char ** const* const* ppcpcpc; - char ****ppppc = (char****)ppcpcpc; - // CHECK-MESSAGES: :[[@LINE-1]]:20: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char ****ppppc = const_cast(ppcpcpc); - - char ***pppc = (char***)*(ppcpcpc); - // CHECK-MESSAGES: :[[@LINE-1]]:18: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char ***pppc = const_cast(*(ppcpcpc)); - - char ***pppc2 = (char***)(*ppcpcpc); - // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-FIXES: char ***pppc2 = const_cast(*ppcpcpc); - - char *pc5 = (char*)(const char*)(cpv); - // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: C-style casts are discouraged. Use const_cast. {{.*}} - // CHECK-MESSAGES: :[[@LINE-2]]:22: warning: C-style casts are discouraged. Use reinterpret_cast. {{.*}} - // CHECK-FIXES: char *pc5 = const_cast(reinterpret_cast(cpv)); - - int b1 = (int)b; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: C-style casts are discouraged. Use static_cast. [google-readability-casting] - // CHECK-FIXES: int b1 = static_cast(b); - - Y *pB = (Y*)pX; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. [google-readability-casting] - Y &rB = (Y&)*pX; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. [google-readability-casting] - - const char *pc3 = (const char*)cpv; - // CHECK-MESSAGES: :[[@LINE-1]]:21: warning: C-style casts are discouraged. Use reinterpret_cast. [google-readability-casting] - // CHECK-FIXES: const char *pc3 = reinterpret_cast(cpv); - - char *pc4 = (char*)cpv; - // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. [google-readability-casting] - // CHECK-FIXES: char *pc4 = (char*)cpv; - - b1 = (int)Enum1; - // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: C-style casts are discouraged. Use static_cast. [google-readability-casting] - // CHECK-FIXES: b1 = static_cast(Enum1); - - Enum e = (Enum)b1; - // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: C-style casts are discouraged. Use static_cast. [google-readability-casting] - // CHECK-FIXES: Enum e = static_cast(b1); - - // CHECK-MESSAGES-NOT: warning: - int b2 = int(b); - int b3 = static_cast(b); - int b4 = b; - double aa = a; - (void)b2; - return (void)g(); -} - -template -void template_function(T t, int n) { - int i = (int)t; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. - // CHECK-FIXES: int i = (int)t; - int j = (int)n; - // CHECK-MESSAGES: :[[@LINE-1]]:11: warning: Redundant cast to the same type. - // CHECK-FIXES: int j = n; -} - -template -struct TemplateStruct { - void f(T t, int n) { - int k = (int)t; - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: C-style casts are discouraged. Use static_cast/const_cast/reinterpret_cast. - // CHECK-FIXES: int k = (int)t; - int l = (int)n; - // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: Redundant cast to the same type. - // CHECK-FIXES: int l = n; - } -}; - -void test_templates() { - template_function(1, 42); - template_function(1.0, 42); - TemplateStruct().f(1, 42); - TemplateStruct().f(1.0, 42); -} - -#define CAST(type, value) (type)(value) -void macros(double d) { - int i = CAST(int, d); -} - -enum E { E1 = 1 }; -template -struct A { - // Usage of template argument e = E1 is represented as (E)1 in the AST for - // some reason. We have a special treatment of this case to avoid warnings - // here. - static const E ee = e; -}; -struct B : public A {}; -- cgit v1.2.3