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

2016-05-11 Thread Piotr Padlewski via cfe-commits
Prazek closed this revision.
Prazek added a comment.

gg for your first check :)


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 Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

Looks good!


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 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-21 Thread Alexander Kornienko via cfe-commits
alexfh requested changes to this revision.
This revision now requires changes to proceed.


Comment at: clang-tidy/modernize/UseBoolLiteralsCheck.cpp:30
@@ +29,3 @@
+
+  Finder->addMatcher(implicitCastExpr(hasIntegerLiteralCastToBool,
+  unless(hasParent(explicitCastExpr(,

Adding two matchers that do almost the same checks is wasteful. You can do the 
same in a single matcher, which will do twice less work:

  implicitCastExpr(has(integerLiteral().bind("literal")),
   hasImplicitDestinationType(qualType(booleanType())),
   unless(isInTemplateInstantiation()),
   hasParent(anyOf(explicitCastExpr().bind("cast"), 
anything(

(if `anything()` here doesn't work, you can probably use `expr()` or something 
else).


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

Can you explain, why is it important to note that this happens "inside a macro"?


Comment at: clang-tidy/modernize/UseBoolLiteralsCheck.cpp:58
@@ +57,3 @@
+
+  if (isPreprocessorDependent(Literal) || isPreprocessorDependent(Cast)) {
+Diag << 1;

I think, you can write `if (Cast) Literal = Cast;` and the rest of the code 
will be much shorter. Also, the `isPreprocessorDependent` doesn't seem to be 
needed.


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-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] D18745: [clang-tidy] Adds modernize-use-bool-literals check.

2016-04-07 Thread Alexander Kornienko via cfe-commits
alexfh requested changes to this revision.
This revision now requires changes to proceed.


Comment at: clang-tidy/modernize/UseBoolLiteralsCheck.cpp:39
@@ +38,3 @@
+
+  return LiteralSource.size() >= 1 && isDigit(LiteralSource.front());
+}

Use `!x.empty()` instead of `x.size() >= 1`.


Comment at: clang-tidy/modernize/UseBoolLiteralsCheck.h:19
@@ +18,3 @@
+
+/// Finds integer literals, which are implicitly cast to bool.
+///

What about the ones explicitly cast to `bool`? Do we want to warn on them?


Comment at: test/clang-tidy/modernize-use-bool-literals.cpp:18
@@ +17,3 @@
+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]
+

Please add CHECK-FIXES to ensure that both the definition of the macro and the 
code using it are not changed.


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-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-06 Thread Marek Sokołowski via cfe-commits
mnbvmar added a comment.

You could also think whether char literals should be converted to true/false, 
too. Apart from this (and other people's doubts), everything's fine.


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-06 Thread Krystyna via cfe-commits
krystyna added a comment.

lgtm


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-06 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a comment.

In http://reviews.llvm.org/D18745#391210, @Prazek wrote:

> In http://reviews.llvm.org/D18745#390739, @Eugene.Zelenko wrote:
>
> > Isn't readability-implicit-bool-cast¶ should catch such issues? If not, I 
> > think will be good idea to improve that check instead of introducing new 
> > one.
>
>
> I wouldn't add this functionality there. I see that 
> readability-implicit-bool-cast aims much different problem.


We have a lot of casts related checks, so may be will be good idea to introduce 
dedicated group for such them?


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-06 Thread Piotr Padlewski via cfe-commits
Prazek added a comment.

So the testing on llvm shows mostly one case - using DEBUG macro like this:

/home/prazek/llvm/lib/Support/APInt.cpp:1656:9: warning: implicitly converting 
integer literal to bool inside macro, use bool literal instead 
[modernize-use-bool-literals]

  DEBUG(dbgs() << " " << r[i]);
  ^

/home/prazek/llvm/include/llvm/Support/Debug.h:92:18: note: expanded from macro 
'DEBUG'
#define DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)

  ^

/home/prazek/llvm/include/llvm/Support/Debug.h:69:48: note: expanded from macro 
'DEBUG_WITH_TYPE'
#define DEBUG_WITH_TYPE(TYPE, X) do { } while (0)

   ^

Some programers maybe would like to supress this in the case of expressions 
like while(1), or specially when it is inside macro. 
What do you think guys? Should we add some special option like 
supress-for-while or supress-macro-while?


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-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"
+