Re: [PATCH] D21303: [clang-tidy] Adds performance-returning-type check.

2016-06-21 Thread Jakub Staroń via cfe-commits
staronj removed rL LLVM as the repository for this revision.
staronj updated this revision to Diff 61402.
staronj marked 8 inline comments as done.
staronj added a comment.

1. Name changed to return-value-copy.
2. Changed warning message.
3. Fixed check description.


http://reviews.llvm.org/D21303

Files:
  clang-tidy/performance/CMakeLists.txt
  clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tidy/performance/ReturnValueCopyCheck.cpp
  clang-tidy/performance/ReturnValueCopyCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/performance-return-value-copy.rst
  test/clang-tidy/performance-return-value-copy.cpp

Index: test/clang-tidy/performance-return-value-copy.cpp
===
--- /dev/null
+++ test/clang-tidy/performance-return-value-copy.cpp
@@ -0,0 +1,305 @@
+// RUN: %check_clang_tidy %s performance-return-value-copy %t
+// CHECK-FIXES: {{^}}#include {{$}}
+
+// we need std::move mock
+namespace std {
+template 
+struct remove_reference { typedef _Tp type; };
+
+template 
+struct remove_reference<_Tp &> { typedef _Tp type; };
+
+template 
+struct remove_reference<_Tp &&> { typedef _Tp type; };
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&
+move(_Tp &&__t) noexcept { return static_cast::type &&>(__t); }
+}
+
+class SimpleClass {
+public:
+  SimpleClass() = default;
+  SimpleClass(const SimpleClass &) = default;
+  SimpleClass(SimpleClass &&) = default;
+
+  // We don't want to add std::move here because it will be added by compiler
+  SimpleClass foo(SimpleClass a, const SimpleClass b, SimpleClass , const SimpleClass , SimpleClass &, const SimpleClass &, char k) {
+switch (k) {
+case 'a':
+  return a;
+case 'b':
+  return b;
+case 'c':
+  return c;
+case 'd':
+  return d;
+case 'e':
+  return e;
+case 'f':
+  return f;
+default:
+  return SimpleClass();
+}
+  }
+};
+
+SimpleClass simpleClassFoo() {
+  return SimpleClass();
+}
+
+class FromValueClass {
+public:
+  FromValueClass(SimpleClass a) {}
+
+  FromValueClass foo(SimpleClass a, const SimpleClass b, SimpleClass , const SimpleClass , SimpleClass &, const SimpleClass &, char k) {
+switch (k) {
+case 'a':
+  // Because SimpleClass is move constructible
+  return a;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: returned object is not moved; consider wrapping it with std::move or changing return type to avoid the copy [performance-return-value-copy]
+// CHECK-FIXES: {{^ *}}return FromValueClass(std::move(a));{{$}}
+case 'b':
+  return b;
+case 'c':
+  return c;
+case 'd':
+  return d;
+case 'e':
+  return e;
+case 'f':
+  return f;
+case 'g':
+  return simpleClassFoo();
+default:
+  return SimpleClass();
+}
+  }
+};
+
+class FromRRefClass {
+public:
+  FromRRefClass() = default;
+  FromRRefClass(const SimpleClass ) {}
+  FromRRefClass(SimpleClass &) {}
+
+  FromRRefClass foo1(SimpleClass a, const SimpleClass b, SimpleClass , const SimpleClass , SimpleClass &, const SimpleClass &, char k) {
+switch (k) {
+case 'a':
+  return a;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{..}}
+// CHECK-FIXES: {{^ *}}return FromRRefClass(std::move(a));{{$}}
+
+// We don't want to add std::move in cases 'b-f because
+case 'b':
+  return b;
+case 'c':
+  return c;
+case 'd':
+  return d;
+case 'e':
+  return e;
+case 'f':
+  return f;
+case 'g':
+  return simpleClassFoo();
+default:
+  return SimpleClass();
+}
+  }
+
+  FromRRefClass foo2(char k) {
+SimpleClass a;
+const SimpleClass  = a;
+SimpleClass  = a;
+SimpleClass *d = 
+const SimpleClass e;
+
+switch (k) {
+case 'a':
+  return a;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{..}}
+// CHECK-FIXES: {{^ *}}return FromRRefClass(std::move(a));{{$}}
+case 'b':
+  return b;
+case 'c':
+  return c;
+case 'd':
+  return *d;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: {{..}}
+// CHECK-FIXES: {{^ *}}return FromRRefClass(std::move(*d));{{$}}
+case 'e':
+  return e;
+case 'f':
+  return simpleClassFoo();
+case 'x':
+  return SimpleClass();
+case 'y':
+  return FromRRefClass(SimpleClass());
+}
+  }
+
+  FromRRefClass foo3(char k) {
+SimpleClass a;
+SimpleClass b;
+FromRRefClass c;
+switch (k) {
+case 'a':
+  return std::move(a);
+case 'b':
+  return FromRRefClass(std::move(a));
+case 'c':
+  return c;
+default:
+  return FromRRefClass();
+}
+  }
+};
+
+template 
+FromRRefClass justTemplateFunction(T &) {
+  return t;
+}
+
+void call_justTemplateFunction() {
+  justTemplateFunction(SimpleClass{});
+  SimpleClass a;
+  justTemplateFunction(a);
+  justTemplateFunction(FromRRefClass{});
+  FromRRefClass b;
+  

Re: [PATCH] D21303: [clang-tidy] Adds performance-returning-type check.

2016-06-21 Thread Jakub Staroń via cfe-commits
staronj added inline comments.


Comment at: clang-tidy/performance/ReturningTypeCheck.cpp:132
@@ +131,3 @@
+  // "constructedType"
+  auto HasTypeSameAsConstructed = hasType(hasCanonicalType(
+  ignoringRefsAndConsts(equalsBoundNode("constructedType";

Prazek wrote:
> I am aware of LLVM style guide, but I think there is exception for the 
> matchers - they looks much more like a matchers when they starts with lower 
> case. I am not sure if it is not spoken rule, but I don't remember single 
> binded matcher that would start with capital case.
See UnnecessaryValueParamCheck.cpp line 33 or LoopConvertCheck.cpp lines 37-47. 
They all start with capital letter.


http://reviews.llvm.org/D21303



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D21303: [clang-tidy] Adds performance-returning-type check.

2016-06-13 Thread Jakub Staroń via cfe-commits
staronj created this revision.
staronj added reviewers: Prazek, alex.
staronj added a subscriber: cfe-commits.

Adds performance-returning-type check.

This check is trying to find places, where one is returning different type than 
function returning type and when returned object is being copied instead of 
moved. Check wraps it with std::move when it could make it being moved.


I ran this check on LLVM codebase and it produced following changes: 
http://reviews.llvm.org/D21302

http://reviews.llvm.org/D21303

Files:
  clang-tidy/performance/CMakeLists.txt
  clang-tidy/performance/PerformanceTidyModule.cpp
  clang-tidy/performance/ReturningTypeCheck.cpp
  clang-tidy/performance/ReturningTypeCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/performance-returning-type.rst
  test/clang-tidy/performance-returning-type.cpp

Index: test/clang-tidy/performance-returning-type.cpp
===
--- /dev/null
+++ test/clang-tidy/performance-returning-type.cpp
@@ -0,0 +1,294 @@
+// RUN: %check_clang_tidy %s performance-returning-type %t
+// CHECK-FIXES: {{^}}#include {{$}}
+
+// we need std::move mock
+namespace std {
+template 
+struct remove_reference { typedef _Tp type; };
+
+template 
+struct remove_reference<_Tp &> { typedef _Tp type; };
+
+template 
+struct remove_reference<_Tp &&> { typedef _Tp type; };
+
+template 
+constexpr typename std::remove_reference<_Tp>::type &&
+move(_Tp &&__t) noexcept { return static_cast::type &&>(__t); }
+}
+
+class SimpleClass {
+public:
+  SimpleClass() = default;
+  SimpleClass(const SimpleClass &) = default;
+  SimpleClass(SimpleClass &&) = default;
+
+  // We don't want to add std::move here because it will be added by compiler
+  SimpleClass foo(SimpleClass a, const SimpleClass b, SimpleClass , const SimpleClass , SimpleClass &, const SimpleClass &, char k) {
+switch (k) {
+case 'a':
+  return a;
+case 'b':
+  return b;
+case 'c':
+  return c;
+case 'd':
+  return d;
+case 'e':
+  return e;
+case 'f':
+  return f;
+default:
+  return SimpleClass();
+}
+  }
+};
+
+SimpleClass simpleClassFoo() {
+  return SimpleClass();
+}
+
+class FromValueClass {
+public:
+  FromValueClass(SimpleClass a) {}
+
+  FromValueClass foo(SimpleClass a, const SimpleClass b, SimpleClass , const SimpleClass , SimpleClass &, const SimpleClass &, char k) {
+switch (k) {
+case 'a':
+  // Because SimpleClass is move constructible
+  return a;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: expression could be wrapped with std::move [performance-returning-type]
+// CHECK-FIXES: {{^ *}}return FromValueClass(std::move(a));{{$}}
+case 'b':
+  return b;
+case 'c':
+  return c;
+case 'd':
+  return d;
+case 'e':
+  return e;
+case 'f':
+  return f;
+case 'g':
+  return simpleClassFoo();
+default:
+  return SimpleClass();
+}
+  }
+};
+
+class FromRRefClass {
+public:
+  FromRRefClass() = default;
+  FromRRefClass(const SimpleClass ) {}
+  FromRRefClass(SimpleClass &) {}
+
+  FromRRefClass foo1(SimpleClass a, const SimpleClass b, SimpleClass , const SimpleClass , SimpleClass &, const SimpleClass &, char k) {
+switch (k) {
+case 'a':
+  return a;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: expression could be wrapped with std::move [performance-returning-type]
+// CHECK-FIXES: {{^ *}}return FromRRefClass(std::move(a));{{$}}
+
+// We don't want to add std::move in cases 'b-f because
+case 'b':
+  return b;
+case 'c':
+  return c;
+case 'd':
+  return d;
+case 'e':
+  return e;
+case 'f':
+  return f;
+// We don't want to add std::move below because it is not necessary (TODO is that true?)
+case 'g':
+  return simpleClassFoo();
+default:
+  return SimpleClass();
+}
+  }
+
+  FromRRefClass foo2(char k) {
+SimpleClass a;
+const SimpleClass  = a;
+SimpleClass  = a;
+SimpleClass *d = 
+const SimpleClass e;
+
+switch (k) {
+case 'a':
+  return a;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: expression could be wrapped with std::move [performance-returning-type]
+// CHECK-FIXES: {{^ *}}return FromRRefClass(std::move(a));{{$}}
+case 'b':
+  return b;
+case 'c':
+  return c;
+case 'd':
+  return *d;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: expression could be wrapped with std::move [performance-returning-type]
+// CHECK-FIXES: {{^ *}}return FromRRefClass(std::move(*d));{{$}}
+case 'e':
+  return e;
+case 'f':
+  return simpleClassFoo();
+case 'x':
+  return SimpleClass();
+case 'y':
+  return FromRRefClass(SimpleClass());
+}
+  }
+
+  FromRRefClass foo3(char k) {
+SimpleClass a;
+SimpleClass b;
+FromRRefClass c;
+switch (k) {
+case 'a':
+  return std::move(a);

Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-05-06 Thread Jakub Staroń via cfe-commits
staronj added inline comments.


Comment at: clang-tidy/modernize/UseBoolLiteralsCheck.cpp:56
@@ +55,3 @@
+   "converting integer literal to "
+   "bool%select{| inside a macro}0, use bool literal instead");
+

alexfh wrote:
> Can you explain, why is it important to note that this happens "inside a 
> macro"?
"Inside a macro" removed.


http://reviews.llvm.org/D18745



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-05-06 Thread Jakub Staroń via cfe-commits
staronj updated this revision to Diff 56395.
staronj marked 3 inline comments as done.

http://reviews.llvm.org/D18745

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-bool-literals.rst
  test/clang-tidy/modernize-use-bool-literals.cpp

Index: test/clang-tidy/modernize-use-bool-literals.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-bool-literals.cpp
@@ -0,0 +1,122 @@
+// RUN: %check_clang_tidy %s modernize-use-bool-literals %t
+
+bool IntToTrue = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool IntToTrue = true;{{$}}
+
+bool IntToFalse(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool IntToFalse(false);{{$}}
+
+bool LongLongToTrue{0x1LL};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool LongLongToTrue{true};{{$}}
+
+bool ExplicitCStyleIntToFalse = (bool)0;
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool ExplicitCStyleIntToFalse = false;{{$}}
+
+bool ExplicitFunctionalIntToFalse = bool(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool ExplicitFunctionalIntToFalse = false;{{$}}
+
+bool ExplicitStaticIntToFalse = static_cast(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool ExplicitStaticIntToFalse = false;{{$}}
+
+#define TRUE_MACRO 1
+// CHECK-FIXES: {{^}}#define TRUE_MACRO 1{{$}}
+
+bool MacroIntToTrue = TRUE_MACRO;
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool MacroIntToTrue = TRUE_MACRO;{{$}}
+
+#define FALSE_MACRO bool(0)
+// CHECK-FIXES: {{^}}#define FALSE_MACRO bool(0){{$}}
+
+
+bool TrueBool = true; // OK
+
+bool FalseBool = bool(FALSE_MACRO);
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool FalseBool = bool(FALSE_MACRO);{{$}}
+
+void boolFunction(bool bar) {
+
+}
+
+char Character = 0; // OK
+
+unsigned long long LongInteger = 1; // OK
+
+#define MACRO_DEPENDENT_CAST(x) static_cast(x)
+// CHECK-FIXES: {{^}}#define MACRO_DEPENDENT_CAST(x) static_cast(x){{$}}
+
+bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:27: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);{{$}}
+
+bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO);
+// CHECK-MESSAGES: :[[@LINE-1]]:49: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool ManyMacrosDependent = MACRO_DEPENDENT_CAST(FALSE_MACRO);{{$}}
+
+class FooClass {
+  public:
+  FooClass() : JustBool(0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}FooClass() : JustBool(false) {}{{$}}
+  FooClass(int) : JustBool{0} {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}FooClass(int) : JustBool{false} {}{{$}}
+  private:
+  bool JustBool;
+  bool BoolWithBraces{0};
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool BoolWithBraces{false};{{$}}
+  bool BoolFromInt = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool BoolFromInt = false;{{$}}
+  bool SimpleBool = true; // OK
+};
+
+template
+void templateFunction(type) {
+  type TemplateType = 0;
+  // CHECK-FIXES: {{^ *}}type TemplateType = 0;{{$}}
+  return;
+}
+
+template
+void valueDependentTemplateFunction() {
+  bool Boolean = c;
+  // CHECK-FIXES: {{^ *}}bool Boolean = c;{{$}}
+  return;
+}
+
+template
+void anotherTemplateFunction(type) {
+  bool JustBool = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool JustBool = false;{{$}}
+  return;
+}
+
+int main() {
+  boolFunction(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}boolFunction(true);{{$}}
+
+  boolFunction(false);
+
+  templateFunction(0);
+
+  templateFunction(false);
+
+  valueDependentTemplateFunction<1>();
+
+  anotherTemplateFunction(1);
+
+  IntToTrue = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}IntToTrue = true;{{$}}
+}
Index: docs/clang-tidy/checks/modernize-use-bool-literals.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-bool-literals.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - modernize-use-bool-literals
+
+modernize-use-bool-literals
+===
+
+Finds integer literals which are cast to bool.
+
+.. code-block:: c++
+
+  bool p = 1;
+  bool f = static_cast(1);
+  std::ios_base::sync_with_stdio(0);
+
+  

Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-19 Thread Jakub Staroń via cfe-commits
staronj marked 5 inline comments as done.
staronj added a comment.

http://reviews.llvm.org/D18745



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-16 Thread Jakub Staroń via cfe-commits
staronj updated the summary for this revision.
staronj updated this revision to Diff 53984.
staronj added a comment.

Check now finds implicit and explicit conversions from integer literal to bool.


http://reviews.llvm.org/D18745

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-bool-literals.rst
  test/clang-tidy/modernize-use-bool-literals.cpp

Index: test/clang-tidy/modernize-use-bool-literals.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-bool-literals.cpp
@@ -0,0 +1,118 @@
+// RUN: %check_clang_tidy %s modernize-use-bool-literals %t
+
+bool IntToTrue = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool IntToTrue = true;{{$}}
+
+bool IntToFalse(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool IntToFalse(false);{{$}}
+
+bool LongLongToTrue{0x1LL};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool LongLongToTrue{true};{{$}}
+
+bool ExplicitCStyleIntToFalse = (bool)0;
+// CHECK-MESSAGES: :[[@LINE-1]]:39: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool ExplicitCStyleIntToFalse = false;{{$}}
+
+bool ExplicitFunctionalIntToFalse = bool(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:42: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool ExplicitFunctionalIntToFalse = false;{{$}}
+
+bool ExplicitStaticIntToFalse = static_cast(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:51: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool ExplicitStaticIntToFalse = false;{{$}}
+
+#define TRUE_MACRO 1
+// CHECK-FIXES: {{^}}#define TRUE_MACRO 1{{$}}
+
+bool MacroIntToTrue = TRUE_MACRO;
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: converting integer literal to bool inside a macro, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool MacroIntToTrue = TRUE_MACRO;{{$}}
+
+#define FALSE_MACRO bool(0)
+// CHECK-FIXES: {{^}}#define FALSE_MACRO bool(0){{$}}
+
+
+bool TrueBool = true; // OK
+
+bool FalseBool = FALSE_MACRO;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool FalseBool = FALSE_MACRO;{{$}}
+
+void boolFunction(bool bar) {
+
+}
+
+char Character = 0; // OK
+
+unsigned long long LongInteger = 1; // OK
+
+#define MACRO_DEPENDENT_CAST(x) static_cast(x)
+// CHECK-FIXES: {{^}}#define MACRO_DEPENDENT_CAST(x) static_cast(x){{$}}
+
+bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:48: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool MacroDependentBool = MACRO_DEPENDENT_CAST(0);{{$}}
+
+class FooClass {
+  public:
+  FooClass() : JustBool(0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}FooClass() : JustBool(false) {}{{$}}
+  FooClass(int) : JustBool{0} {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}FooClass(int) : JustBool{false} {}{{$}}
+  private:
+  bool JustBool;
+  bool BoolWithBraces{0};
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool BoolWithBraces{false};{{$}}
+  bool BoolFromInt = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool BoolFromInt = false;{{$}}
+  bool SimpleBool = true; // OK
+};
+
+template
+void templateFunction(type) {
+  type TemplateType = 0;
+  // CHECK-FIXES: {{^ *}}type TemplateType = 0;{{$}}
+  return;
+}
+
+template
+void valueDependentTemplateFunction() {
+  bool Boolean = c;
+  // CHECK-FIXES: {{^ *}}bool Boolean = c;{{$}}
+  return;
+}
+
+template
+void anotherTemplateFunction(type) {
+  bool JustBool = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:19: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool JustBool = false;{{$}}
+  return;
+}
+
+int main() {
+  boolFunction(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}boolFunction(true);{{$}}
+
+  boolFunction(false);
+
+  templateFunction(0);
+
+  templateFunction(false);
+
+  valueDependentTemplateFunction<1>();
+
+  anotherTemplateFunction(1);
+
+  IntToTrue = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}IntToTrue = true;{{$}}
+}
Index: docs/clang-tidy/checks/modernize-use-bool-literals.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-bool-literals.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - modernize-use-bool-literals
+
+modernize-use-bool-literals
+===
+
+Finds integer literals which are cast to bool.
+
+.. code-block:: c++
+
+  bool p = 1;
+  bool f = static_cast(1);
+  std::ios_base::sync_with_stdio(0);
+
+  // transforms to
+
+  bool p = true;
+  bool f = true;
+  

Re: [PATCH] D18919: Add check "modernize use using"

2016-04-09 Thread Jakub Staroń via cfe-commits
staronj added inline comments.


Comment at: clang-tidy/modernize/UseUsingCheck.h:19
@@ +18,3 @@
+
+/// FIXME: Write a short description.
+///

Fix the FIXME.


Comment at: test/clang-tidy/modernize-use-using.cpp:76
@@ +75,1 @@
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
\ No newline at end of file


Add end of line at the end of file.


http://reviews.llvm.org/D18919



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-06 Thread Jakub Staroń via cfe-commits
staronj updated this revision to Diff 52843.
staronj added a comment.

1. Adds newline at the end of modernize-use-bool-literals.rst file.
2. Change names in check test for better readability.
3. Adds some new test cases.


http://reviews.llvm.org/D18745

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-bool-literals.rst
  test/clang-tidy/modernize-use-bool-literals.cpp

Index: test/clang-tidy/modernize-use-bool-literals.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-bool-literals.cpp
@@ -0,0 +1,63 @@
+// RUN: %check_clang_tidy %s modernize-use-bool-literals %t
+
+bool IntToTrue = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicitly converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool IntToTrue = true;{{$}}
+
+bool IntToFalse(0);
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool IntToFalse(false);{{$}}
+
+bool LongLongToTrue{0x123ABCLL};
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool LongLongToTrue{true};{{$}}
+
+#define TRUE_MACRO 1
+
+bool MacroIntToTrue = TRUE_MACRO; // Not ok, but can't replace
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: implicitly converting integer literal to bool inside macro, use bool literal instead [modernize-use-bool-literals]
+
+#define FALSE_MACRO bool(0)
+
+bool TrueBool = true; // OK
+
+bool FalseBool = FALSE_MACRO;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: {{.*}}
+
+void boolFunction(bool bar) {
+
+}
+
+char Character = 0; // OK
+unsigned long long LongInteger = 1; // OK
+
+int main() {
+  boolFunction(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:16: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}boolFunction(true);{{$}}
+
+  boolFunction(false); // OK
+
+  IntToTrue = 1;
+  // CHECK-MESSAGES: :[[@LINE-1]]:15: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}IntToTrue = true;{{$}}
+}
+
+class FooClass {
+  public:
+  FooClass() : JustBool(0) {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:25: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}FooClass() : JustBool(false) {}{{$}}
+  FooClass(int) : JustBool{0} {}
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}FooClass(int) : JustBool{false} {}{{$}}
+  private:
+  bool JustBool;
+  bool BoolWithBraces{0};
+  // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool BoolWithBraces{false};{{$}}
+  bool BoolFromInt = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:22: warning: {{.*}}
+  // CHECK-FIXES: {{^ *}}bool BoolFromInt = false;{{$}}
+  bool SimpleBool = true; // OK
+};
Index: docs/clang-tidy/checks/modernize-use-bool-literals.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-bool-literals.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - modernize-use-bool-literals
+
+modernize-use-bool-literals
+===
+
+Finds integer literals, which are implicitly cast to bool.
+
+.. code-block:: c++
+
+  bool p = 1;
+  std::ios_base::sync_with_stdio(0);
+
+  // transforms to
+
+  bool p = true;
+  std::ios_base::sync_with_stdio(false);
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -85,6 +85,7 @@
modernize-replace-auto-ptr
modernize-shrink-to-fit
modernize-use-auto
+   modernize-use-bool-literals
modernize-use-default
modernize-use-nullptr
modernize-use-override
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -119,6 +119,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-bool-literals
+  `_ check
+
+  Finds integer literals, which are implicitly cast to bool.
+
 - New `performance-faster-string-find
   

Re: [PATCH] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-05 Thread Jakub Staroń via cfe-commits
staronj retitled this revision from "[clang-tidy] Adds misc-use-bool-literals 
check." to "[clang-tidy] Adds modernize-use-bool-literals check.".
staronj updated this revision to Diff 52739.
staronj added a comment.

1. Name changed from misc-use-bool-literals to modernize-use-bool-literals.
2. Code clang-formatted.
3. Check ran on LLVM code.


http://reviews.llvm.org/D18745

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.cpp
  clang-tidy/modernize/UseBoolLiteralsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-bool-literals.rst
  test/clang-tidy/modernize-use-bool-literals.cpp

Index: test/clang-tidy/modernize-use-bool-literals.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-bool-literals.cpp
@@ -0,0 +1,41 @@
+// RUN: %check_clang_tidy %s modernize-use-bool-literals %t
+
+bool bar1 = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: implicitly converting integer literal to bool, use bool literal instead [modernize-use-bool-literals]
+// CHECK-FIXES: {{^}}bool bar1 = true;{{$}}
+
+bool bar2 = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool bar2 = false;{{$}}
+
+bool bar3 = 0x123ABCLL;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: {{.*}}
+// CHECK-FIXES: {{^}}bool bar3 = true;{{$}}
+
+#define TRUE_FALSE 1
+
+bool bar4 = TRUE_FALSE;
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: implicitly converting integer literal to bool inside macro, use bool literal instead [modernize-use-bool-literals]
+
+#define TRUE_FALSE2 bool(1) // OK
+
+bool bar6 = true; // OK
+
+void foo4(bool bar) {
+
+}
+
+char bar7 = 0;
+unsigned long long bar8 = 1;
+
+int main() {
+  foo4(1);
+  // CHECK-MESSAGES: :[[@LINE-1]]:8: warning: {{.*}}
+  // CHECK-FIXES: {{^}}  foo4(true);{{$}}
+
+  foo4(false); // OK
+
+  bar1 = 0;
+  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: {{.*}}
+  // CHECK-FIXES: {{^}}  bar1 = false;{{$}}
+}
Index: docs/clang-tidy/checks/modernize-use-bool-literals.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-bool-literals.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - modernize-use-bool-literals
+
+modernize-use-bool-literals
+===
+
+Finds integer literals, which are implicitly cast to bool.
+
+.. code-block:: c++
+
+  bool p = 1;
+  std::ios_base::sync_with_stdio(0);
+
+  // transforms to
+
+  bool p = true;
+  std::ios_base::sync_with_stdio(false);
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -85,6 +85,7 @@
modernize-replace-auto-ptr
modernize-shrink-to-fit
modernize-use-auto
+   modernize-use-bool-literals
modernize-use-default
modernize-use-nullptr
modernize-use-override
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -119,6 +119,11 @@
   Selectively replaces string literals containing escaped characters with raw
   string literals.
 
+- New `modernize-use-bool-literals
+  `_ check
+
+  Finds integer literals, which are implicitly cast to bool.
+
 - New `performance-faster-string-find
   `_ check
 
Index: clang-tidy/modernize/UseBoolLiteralsCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseBoolLiteralsCheck.h
@@ -0,0 +1,35 @@
+//===--- UseBoolLiteralsCheck.h - clang-tidy-*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_BOOL_LITERALS_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_BOOL_LITERALS_H
+
+#include "../ClangTidy.h"
+