blob: 488bcd796370fa933a157fcde202b483f1915121 [file] [log] [blame]
Manuel Klimek8f9e4442015-10-22 14:54:50 +00001// RUN: %check_clang_tidy %s google-readability-casting %t -- -- -x c
Alexander Kornienko19bbeaf2015-05-21 14:08:56 +00002// The testing script always adds .cpp extension to the input file name, so we
3// need to run clang-tidy directly in order to verify handling of .c files:
4// RUN: clang-tidy --checks=-*,google-readability-casting %s -- -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
Alexander Kornienko2b566492015-05-26 10:47:48 +00005// RUN: cp %s %t.main_file.cpp
6// RUN: clang-tidy --checks=-*,google-readability-casting -header-filter='.*' %t.main_file.cpp -- -I%S -DTEST_INCLUDE -x c++ | FileCheck %s -check-prefix=CHECK-MESSAGES -implicit-check-not='{{warning|error}}:'
Alexander Kornienko02bd0182014-09-21 23:39:28 +00007
Alexander Kornienko2b566492015-05-26 10:47:48 +00008#ifdef TEST_INCLUDE
9
10#undef TEST_INCLUDE
11#include "google-readability-casting.c"
12
13#else
14
Alexander Kornienko02bd0182014-09-21 23:39:28 +000015void f(const char *cpc) {
16 const char *cpc2 = (const char*)cpc;
Alexander Kornienko78070fb2015-01-29 15:17:13 +000017 // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: redundant cast to the same type [google-readability-casting]
Alexander Kornienko02bd0182014-09-21 23:39:28 +000018 // CHECK-FIXES: const char *cpc2 = cpc;
19 char *pc = (char*)cpc;
Alexander Kornienkodb04ccc2017-03-03 08:18:49 +000020 typedef const char *Typedef1;
21 (Typedef1)cpc;
Alexander Kornienko02bd0182014-09-21 23:39:28 +000022}
Alexander Kornienko2b566492015-05-26 10:47:48 +000023
24#endif