Disable most of the google-readability-casting check for non-C++ files (only

leave the "redundant cast to the same type" part).

llvm-svn: 218225
This commit is contained in:
Alexander Kornienko 2014-09-21 23:39:28 +00:00
parent b195e860f9
commit 02bd018aeb
3 changed files with 18 additions and 1 deletions

View File

@ -78,6 +78,10 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
return;
}
// The rest of this check is only relevant to C++.
if (!Result.Context->getLangOpts().CPlusPlus)
return;
std::string DestTypeString = CastExpr->getTypeAsWritten().getAsString();
auto diag_builder =

View File

@ -0,0 +1,9 @@
// RUN: $(dirname %s)/check_clang_tidy_fix.sh %s google-readability-casting %t -x c
// REQUIRES: shell
void f(const char *cpc) {
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;
}

View File

@ -14,6 +14,10 @@ CHECK_TO_RUN=$2
TEMPORARY_FILE=$3.cpp
# Feed the rest arguments to clang-tidy after --.
shift 3
CLANG_TIDY_ARGS=--std=c++11
if (($# > 0)) ; then
CLANG_TIDY_ARGS=$*
fi
set -o errexit
@ -23,7 +27,7 @@ set -o errexit
sed 's#// *CHECK-[A-Z-]*:.*#//#' ${INPUT_FILE} > ${TEMPORARY_FILE}
clang-tidy ${TEMPORARY_FILE} -fix --checks="-*,${CHECK_TO_RUN}" \
-- --std=c++11 $* > ${TEMPORARY_FILE}.msg 2>&1
-- ${CLANG_TIDY_ARGS} > ${TEMPORARY_FILE}.msg 2>&1
FileCheck -input-file=${TEMPORARY_FILE} ${INPUT_FILE} \
-check-prefix=CHECK-FIXES -strict-whitespace