[clang-tools-extra] r218225 - Disable most of the google-readability-casting check for non-C++ files (only

Alexander Kornienko alexfh at google.com
Sun Sep 21 16:39:28 PDT 2014


Author: alexfh
Date: Sun Sep 21 18:39:28 2014
New Revision: 218225

URL: http://llvm.org/viewvc/llvm-project?rev=218225&view=rev
Log:
Disable most of the google-readability-casting check for non-C++ files (only
leave the "redundant cast to the same type" part).

Added:
    clang-tools-extra/trunk/test/clang-tidy/avoid-c-style-casts.c
Modified:
    clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
    clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh

Modified: clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp?rev=218225&r1=218224&r2=218225&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/AvoidCStyleCastsCheck.cpp Sun Sep 21 18:39:28 2014
@@ -78,6 +78,10 @@ void AvoidCStyleCastsCheck::check(const
     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 =

Added: clang-tools-extra/trunk/test/clang-tidy/avoid-c-style-casts.c
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/avoid-c-style-casts.c?rev=218225&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/avoid-c-style-casts.c (added)
+++ clang-tools-extra/trunk/test/clang-tidy/avoid-c-style-casts.c Sun Sep 21 18:39:28 2014
@@ -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;
+}

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh?rev=218225&r1=218224&r2=218225&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh Sun Sep 21 18:39:28 2014
@@ -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





More information about the cfe-commits mailing list