From 276fc642d38bbaa4aca00f517ba2f6f7bd138fe3 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Sun, 29 Jun 2014 22:19:53 +0000 Subject: Another attempt to add a clang-tidy check for flagging C-style casts. Summary: The first version failed the SubstNonTypeTempateParmExpr-related test on some buildbots. This one uses the new substNonTypeTempateParmExpr matcher to filter out implicit C-style casts. This patch depends on D4327. Reviewers: djasper Reviewed By: djasper Subscribers: aemerson, cfe-commits Differential Revision: http://reviews.llvm.org/D4328 llvm-svn: 212002 --- .../test/clang-tidy/avoid-c-style-casts.cpp | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create 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 new file mode 100644 index 00000000000..8b9feb43d93 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/avoid-c-style-casts.cpp @@ -0,0 +1,24 @@ +// RUN: clang-tidy -checks=-*,google-readability-casting %s -- | FileCheck %s + +// CHECK-NOT: warning: + +bool g() { return false; } + +void f(int a, double b) { + int b1 = (int)b; + // CHECK: :[[@LINE-1]]:12: warning: C-style casts are discouraged. Use static_cast{{.*}} + + // CHECK-NOT: warning: + int b2 = int(b); + int b3 = static_cast(b); + int b4 = b; + double aa = a; + (void)b2; + return (void)g(); +} + +// CHECK-NOT: warning: +enum E { E1 = 1 }; +template +struct A { static const E ee = e; }; +struct B : public A {}; -- cgit v1.2.3