[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-10-11 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik added inline comments.



Comment at: clang-tidy/misc/CopyConstructorInitCheck.cpp:37
+
+  // We match here because we want one warning (and FixIt) for every ctor.
+  const auto Matches = match(

aaron.ballman wrote:
> Wouldn't registering this matcher achieve the same goal instead of needing to 
> re-match?
I wanted to create //only one// FixIt to every ctor - if I move the 
forEachCtorInitializer to the register part, it would warn us twice.



Comment at: clang-tidy/misc/CopyConstructorInitCheck.cpp:104
+
+  diag(Tok.getLocation(),
+   "calling an inherited constructor other than the copy constructor")

aaron.ballman wrote:
> Insteaad of having to re-lex the physical source, can the AST should be 
> modified to carry the information you need if it doesn't already have it? For 
> instance, you can tell there is not initializer list by looking at 
> `CXXConstructorDecl::getNumCtorInitializers()`.
The getNumCtorInitializers method counts the generated initializers as well, 
not just the manually written ones.
My basic problem was that the AST's methods can't really distinguish the 
generated and the manually written initializers, so it's quite complicated to 
find the locations what we need. I found easier & more understandable if I 
start reading the tokens.



Comment at: test/clang-tidy/misc-copy-constructor-init.cpp:27
+   // CHECK-MESSAGES: :[[@LINE-1]]:23: warning: calling an inherited 
constructor other than the copy constructor [misc-copy-constructor-init]
+   // CHECK-FIXES: X3(const X3& other): Copyable2(other), Copyable(other) 
{};
+};

aaron.ballman wrote:
> Don't we want the ctor-inits to be in the same order as the bases are 
> specified?
I think it's more readable if we put the FixIts to the beginning of the 
expression - it's easier to check that everyting is correct & it's more obvious 
what the changes are.


https://reviews.llvm.org/D33722



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


[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-10-11 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik updated this revision to Diff 118617.
szdominik marked 4 inline comments as done.
szdominik added a comment.

Small changes after aaron.ballman's comments.


https://reviews.llvm.org/D33722

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/CopyConstructorInitCheck.cpp
  clang-tidy/misc/CopyConstructorInitCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-copy-constructor-init.rst
  test/clang-tidy/misc-copy-constructor-init.cpp

Index: test/clang-tidy/misc-copy-constructor-init.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-copy-constructor-init.cpp
@@ -0,0 +1,95 @@
+// RUN: %check_clang_tidy %s misc-copy-constructor-init %t
+
+class Copyable {
+	public:
+	Copyable() = default;
+	Copyable(const Copyable&) = default;
+};
+class X : public Copyable {
+	X(const X& other) : Copyable(other) {}
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class Copyable2 {
+	public:
+	Copyable2() = default;
+	Copyable2(const Copyable2&) = default;
+};
+class X2 : public Copyable2 {
+	X2(const X2& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X2(const X2& other) : Copyable2(other) {};
+};
+
+class X3 : public Copyable, public Copyable2 {
+	X3(const X3& other): Copyable(other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X3(const X3& other): Copyable2(other), Copyable(other) {};
+};
+
+class X4 : public Copyable {
+	X4(const X4& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X4(const X4& other): Copyable(other) {};
+};
+
+class Copyable3 : public Copyable {
+	public:
+	Copyable3() = default;
+	Copyable3(const Copyable3&) = default;
+};
+class X5 : public Copyable3 {
+	X5(const X5& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X5(const X5& other) : Copyable3(other) {};
+};
+
+class X6 : public Copyable2, public Copyable3 {
+	X6(const X6& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X6(const X6& other) : Copyable2(other), Copyable3(other) {};
+};
+
+class X7 : public Copyable, public Copyable2 {
+	X7(const X7& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-MESSAGES: :[[@LINE-2]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X7(const X7& other): Copyable2(other), Copyable(other) {};
+};
+
+template 
+class Copyable4 {
+	public:
+	Copyable4() = default;
+	Copyable4(const Copyable4&) = default;
+};
+
+class X8 : public Copyable4 {
+	X8(const X8& other): Copyable4(other) {};
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class X9 : public Copyable4 {
+	X9(const X9& other): Copyable4() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X9(const X9& other): Copyable4(other) {};
+};
+
+class X10 : public Copyable4 {
+	X10(const X10& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X10(const X10& other) : Copyable4(other) {};
+};
+
+template 
+class Copyable5 {
+	public:
+	Copyable5() = default;
+	Copyable5(const Copyable5&) = default;
+};
+
+class X11 : public Copyable5 {
+	X11(const X11& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X11(const X11& other) : Copyable5(other) {};
+};
Index: docs/clang-tidy/checks/misc-copy-constructor-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-copy-constructor-init.rst
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - misc-copy-constructor-init
+
+misc-copy-constructor-init
+=
+
+Finds copy constructors where the constructor don't call 
+the constructor of the base class.
+
+.. code-block:: c++
+
+class Copyable {
+public:
+Copyable() = default;
+Copyable(const Copyable&) = default;
+};
+class X2 : public Copyable {
+X2(const X2& other) {}; // 

[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-09-18 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik added a comment.

There wasn't any update on this check lately - can I help to make it better?


https://reviews.llvm.org/D33722



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


[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-08-03 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik updated this revision to Diff 109564.
szdominik marked 2 inline comments as done.
szdominik added a comment.
Herald added a subscriber: JDevlieghere.

Fixed check-fixes lines in test cases.
Updated matcher definition.


https://reviews.llvm.org/D33722

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/CopyConstructorInitCheck.cpp
  clang-tidy/misc/CopyConstructorInitCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-copy-constructor-init.rst
  test/clang-tidy/misc-copy-constructor-init.cpp

Index: test/clang-tidy/misc-copy-constructor-init.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-copy-constructor-init.cpp
@@ -0,0 +1,95 @@
+// RUN: %check_clang_tidy %s misc-copy-constructor-init %t
+
+class Copyable {
+	public:
+	Copyable() = default;
+	Copyable(const Copyable&) = default;
+};
+class X : public Copyable {
+	X(const X& other) : Copyable(other) {}
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class Copyable2 {
+	public:
+	Copyable2() = default;
+	Copyable2(const Copyable2&) = default;
+};
+class X2 : public Copyable2 {
+	X2(const X2& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X2(const X2& other) : Copyable2(other) {};
+};
+
+class X3 : public Copyable, public Copyable2 {
+	X3(const X3& other): Copyable(other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X3(const X3& other): Copyable2(other), Copyable(other) {};
+};
+
+class X4 : public Copyable {
+	X4(const X4& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X4(const X4& other): Copyable(other) {};
+};
+
+class Copyable3 : public Copyable {
+	public:
+	Copyable3() = default;
+	Copyable3(const Copyable3&) = default;
+};
+class X5 : public Copyable3 {
+	X5(const X5& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X5(const X5& other) : Copyable3(other) {};
+};
+
+class X6 : public Copyable2, public Copyable3 {
+	X6(const X6& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X6(const X6& other) : Copyable2(other), Copyable3(other) {};
+};
+
+class X7 : public Copyable, public Copyable2 {
+	X7(const X7& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-MESSAGES: :[[@LINE-2]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X7(const X7& other): Copyable2(other), Copyable(other) {};
+};
+
+template 
+class Copyable4 {
+	public:
+	Copyable4() = default;
+	Copyable4(const Copyable4&) = default;
+};
+
+class X8 : public Copyable4 {
+	X8(const X8& other): Copyable4(other) {};
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class X9 : public Copyable4 {
+	X9(const X9& other): Copyable4() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X9(const X9& other): Copyable4(other) {};
+};
+
+class X10 : public Copyable4 {
+	X10(const X10& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X10(const X10& other) : Copyable4(other) {};
+};
+
+template 
+class Copyable5 {
+	public:
+	Copyable5() = default;
+	Copyable5(const Copyable5&) = default;
+};
+
+class X11 : public Copyable5 {
+	X11(const X11& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: X11(const X11& other) : Copyable5(other) {};
+};
Index: docs/clang-tidy/checks/misc-copy-constructor-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-copy-constructor-init.rst
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - misc-copy-constructor-init
+
+misc-copy-constructor-init
+=
+
+Finds copy constructors where the constructor don't call 
+the constructor of the base class.
+
+.. code-block:: c++
+
+class Copyable {
+public:
+Copyable() = default;
+Copyable(const Copyable&) = default;
+};
+class X2 : 

[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-07-12 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik added a comment.

In https://reviews.llvm.org/D33645#806852, @dcoughlin wrote:

> Do you have commit access, or do you need someone to commit it for you?


Thank you.
I don't have, I'm quite new at this project. :)


https://reviews.llvm.org/D33645



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


[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-07-12 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik updated this revision to Diff 106184.
szdominik marked 9 inline comments as done.
szdominik added a comment.

Update with more idiomatic examples (from @dcoughlin).


https://reviews.llvm.org/D33645

Files:
  www/analyzer/alpha_checks.html
  www/analyzer/available_checks.html
  www/analyzer/implicit_checks.html

Index: www/analyzer/implicit_checks.html
===
--- www/analyzer/implicit_checks.html
+++ www/analyzer/implicit_checks.html
@@ -27,7 +27,7 @@
 OS X Implicit Checkers
 
 
-
+
 Core Implicit Checkers
 
 
@@ -124,7 +124,7 @@
 
 
 
-
+
 OS X Implicit Checkers
 
 
Index: www/analyzer/available_checks.html
===
--- www/analyzer/available_checks.html
+++ www/analyzer/available_checks.html
@@ -38,12 +38,14 @@
 Core Checkers model core language features and perform general-purpose checks such as division by zero, null pointer dereference, usage of uninitialized values, etc.
 C++ Checkers perform C++-specific checks
 Dead Code Checkers check for unused code
+Nullability Checkers 
+Optin Checkers 
 OS X Checkers perform Objective-C-specific checks and check the use of Apple's SDKs (OS X and iOS)
 Security Checkers check for insecure API usage and perform checks based on the CERT Secure Coding Standards
 Unix Checkers check the use of Unix and POSIX APIs
 
 
-
+
 Core Checkers
 
 
@@ -360,7 +362,7 @@
 
 
 
-
+
 C++ Checkers
 
 
@@ -421,9 +423,21 @@
 }
 
 
+
+cplusplus.NewDeleteLeaks
+(C++)
+Check for memory leaks. Traces memory managed by new/
+delete.
+
+
+void test() {
+  int *p = new int;
+} // warn
+
+
 
 
-
+
 Dead Code Checkers
 
 
@@ -444,7 +458,161 @@
 
 
 
-
+
+Nullability Checkers
+
+
+Name, DescriptionExample
+
+
+
+nullability.NullPassedToNonnull
+(ObjC)
+Warns when a null pointer is passed to a pointer which has a 
+_Nonnull type.
+
+
+if (name != nil)
+  return;
+// Warning: nil passed to a callee that requires a non-null 1st parameter
+NSString *greeting = [@"Hello " stringByAppendingString:name];
+
+
+
+
+nullability.NullReturnedFromNonnull
+(ObjC)
+Warns when a null pointer is returned from a function that has 
+_Nonnull return type.
+
+
+- (nonnull id)firstChild {
+  id result = nil;
+  if ([_children count] > 0)
+result = _children[0];
+
+  // Warning: nil returned from a method that is expected 
+  // to return a non-null value
+  return result;
+}
+
+
+
+
+nullability.NullableDereferenced
+(ObjC)
+Warns when a nullable pointer is dereferenced.
+
+
+struct LinkedList {
+  int data;
+  struct LinkedList *next;
+};
+
+struct LinkedList * _Nullable getNext(struct LinkedList *l);
+
+void updateNextData(struct LinkedList *list, int newData) {
+  struct LinkedList *next = getNext(list);
+  // Warning: Nullable pointer is dereferenced
+  next->data = 7;
+}
+
+
+
+
+nullability.NullablePassedToNonnull
+(ObjC)
+Warns when a nullable pointer is passed to a pointer which has a _Nonnull type.
+
+
+typedef struct Dummy { int val; } Dummy;
+Dummy *_Nullable returnsNullable();
+void takesNonnull(Dummy *_Nonnull);
+
+void test() {
+  Dummy *p = returnsNullable();
+  takesNonnull(p); // warn
+}
+
+
+
+
+
+Optin Checkers
+
+
+Name, DescriptionExample
+
+
+
+optin.mpi.MPI-Checker
+(C)
+Checks MPI code
+
+
+void test() {
+  double buf = 0;
+  MPI_Request sendReq1;
+  MPI_Ireduce(MPI_IN_PLACE, , 1, MPI_DOUBLE, MPI_SUM, 
+  0, MPI_COMM_WORLD, );
+} // warn: request 'sendReq1' has no matching wait.
+
+
+void test() {
+  double buf = 0;
+  MPI_Request sendReq;
+  MPI_Isend(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, );
+  MPI_Irecv(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, ); // warn
+  MPI_Isend(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, ); // warn
+  MPI_Wait(, MPI_STATUS_IGNORE);
+}
+
+
+void missingNonBlocking() {
+  int rank = 0;
+  MPI_Comm_rank(MPI_COMM_WORLD, );
+  MPI_Request sendReq1[10][10][10];
+  MPI_Wait([1][7][9], MPI_STATUS_IGNORE); // warn
+}
+
+
+
+
+optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
+(ObjC)
+Check that NSLocalizedString macros include a comment for context.
+
+
+- (void)test {
+  NSString *string = NSLocalizedString(@"LocalizedString", nil); // warn
+  NSString *string2 = NSLocalizedString(@"LocalizedString", @" "); // warn
+  NSString *string3 = NSLocalizedStringWithDefaultValue(
+@"LocalizedString", nil, [[NSBundle alloc] init], nil,@""); // warn
+}
+
+
+
+
+optin.osx.cocoa.localizability.NonLocalizedStringChecker
+(ObjC)
+Warns about uses of non-localized NSStrings passed to UI methods 
+expecting localized NSStrings
+
+
+NSString *alarmText = 
+  NSLocalizedString(@"Enabled", @"Indicates alarm is turned on");
+if (!isEnabled) {
+  alarmText = @"Disabled";
+}
+UILabel *alarmStateLabel = [[UILabel alloc] init];
+
+// Warning: User-facing text should use localized string macro
+[alarmStateLabel setText:alarmText];
+
+
+
+
+
 OS X Checkers
 
 
@@ -466,6 +634,22 @@
 
 
 
+osx.NumberObjectConversion
+(C, C++, ObjC)
+Check for erroneous 

[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-07-12 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik added a comment.

In https://reviews.llvm.org/D33645#805920, @dcoughlin wrote:

> Who is the target of this documentation? Is it developers of the analyzer or 
> is it end users of the analyzer? If it is end users, it is unfortunate that 
> we've been just grabbing examples from the regression tests. These tests are 
> usually not idiomatic and, since they're designed for testing, they typically 
> won't explain the check well to an end user.
>
> I've suggested some more idiomatic examples inline for for some of the 
> Objective-C targeted checkers -- but it is probably worth thinking about the 
> remaining examples from the perspective of an end user.


Thank you for the examples, I'll update the patch.
I think the target is the end users, so you're right, probably more idiomatic 
examples would be better. (And @NoQ is right with warning messages too - but it 
should be reconsider the whole documentation, because it doesn't have really 
recognizable convention for that.)
However I'm not very good with Objective-C, so probably I'm not the best for 
this task :)


https://reviews.llvm.org/D33645



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


[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-06-21 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik updated this revision to Diff 103385.
szdominik marked 4 inline comments as done.
szdominik added a comment.

Updated loop for searching the beginning of the initlist.


https://reviews.llvm.org/D33722

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/CopyConstructorInitCheck.cpp
  clang-tidy/misc/CopyConstructorInitCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-copy-constructor-init.rst
  test/clang-tidy/misc-copy-constructor-init.cpp

Index: test/clang-tidy/misc-copy-constructor-init.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-copy-constructor-init.cpp
@@ -0,0 +1,96 @@
+// RUN: %check_clang_tidy %s misc-copy-constructor-init %t
+
+class Copyable {
+	public:
+	Copyable() = default;
+	Copyable(const Copyable&) = default;
+};
+class X : public Copyable {
+	X(const X& other) : Copyable(other) {}
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class Copyable2 {
+	public:
+	Copyable2() = default;
+	Copyable2(const Copyable2&) = default;
+};
+class X2 : public Copyable2 {
+	X2(const X2& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable2(other)
+};
+
+class X3 : public Copyable, public Copyable2 {
+	X3(const X3& other): Copyable(other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: Copyable2(other), 
+};
+
+class X4 : public Copyable {
+	X4(const X4& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: other
+};
+
+class Copyable3 : public Copyable {
+	public:
+	Copyable3() = default;
+	Copyable3(const Copyable3&) = default;
+};
+class X5 : public Copyable3 {
+	X5(const X5& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable3(other)
+};
+
+class X6 : public Copyable2, public Copyable3 {
+	X6(const X6& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable2(other), Copyable3(other)
+};
+
+class X7 : public Copyable, public Copyable2 {
+	X7(const X7& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: other
+	// CHECK-MESSAGES: :[[@LINE-3]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: Copyable2(other), 
+};
+
+template 
+class Copyable4 {
+	public:
+	Copyable4() = default;
+	Copyable4(const Copyable4&) = default;
+};
+
+class X8 : public Copyable4 {
+	X8(const X8& other): Copyable4(other) {};
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class X9 : public Copyable4 {
+	X9(const X9& other): Copyable4() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: other
+};
+
+class X10 : public Copyable4 {
+	X10(const X10& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable4(other)
+};
+
+template 
+class Copyable5 {
+	public:
+	Copyable5() = default;
+	Copyable5(const Copyable5&) = default;
+};
+
+class X11 : public Copyable5 {
+	X11(const X11& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable5(other)
+};
Index: docs/clang-tidy/checks/misc-copy-constructor-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-copy-constructor-init.rst
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - misc-copy-constructor-init
+
+misc-copy-constructor-init
+=
+
+Finds copy constructors where the constructor don't call 
+the constructor of the base class.
+
+.. code-block:: c++
+
+class Copyable {
+public:
+Copyable() = default;
+Copyable(const Copyable&) = default;
+};
+class X2 : public Copyable {
+X2(const X2& other) {}; // Copyable(other) is missing
+};
+
+Also finds copy constructors where the constructor of 
+the base class don't have parameter. 
+
+.. code-block:: c++
+
+class X4 : public Copyable {
+X4(const X4& other): Copyable() {}; // other is 

[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-06-21 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik updated this revision to Diff 103378.
szdominik marked 3 inline comments as done.
szdominik added a comment.

Fixed alpha.core.CallAndMessageUnInitRefArg.


https://reviews.llvm.org/D33645

Files:
  www/analyzer/alpha_checks.html
  www/analyzer/available_checks.html
  www/analyzer/implicit_checks.html

Index: www/analyzer/implicit_checks.html
===
--- www/analyzer/implicit_checks.html
+++ www/analyzer/implicit_checks.html
@@ -27,7 +27,7 @@
 OS X Implicit Checkers
 
 
-
+
 Core Implicit Checkers
 
 
@@ -124,7 +124,7 @@
 
 
 
-
+
 OS X Implicit Checkers
 
 
Index: www/analyzer/available_checks.html
===
--- www/analyzer/available_checks.html
+++ www/analyzer/available_checks.html
@@ -38,12 +38,14 @@
 Core Checkers model core language features and perform general-purpose checks such as division by zero, null pointer dereference, usage of uninitialized values, etc.
 C++ Checkers perform C++-specific checks
 Dead Code Checkers check for unused code
+Nullability Checkers 
+Optin Checkers 
 OS X Checkers perform Objective-C-specific checks and check the use of Apple's SDKs (OS X and iOS)
 Security Checkers check for insecure API usage and perform checks based on the CERT Secure Coding Standards
 Unix Checkers check the use of Unix and POSIX APIs
 
 
-
+
 Core Checkers
 
 
@@ -360,7 +362,7 @@
 
 
 
-
+
 C++ Checkers
 
 
@@ -421,9 +423,21 @@
 }
 
 
+
+cplusplus.NewDeleteLeaks
+(C++)
+Check for memory leaks. Traces memory managed by new/
+delete.
+
+
+void test() {
+  int *p = new int;
+} // warn
+
+
 
 
-
+
 Dead Code Checkers
 
 
@@ -444,7 +458,157 @@
 
 
 
-
+
+Nullability Checkers
+
+
+Name, DescriptionExample
+
+
+
+nullability.NullPassedToNonnull
+(ObjC)
+Warns when a null pointer is passed to a pointer which has a 
+_Nonnull type.
+
+
+typedef struct Dummy { int val; } Dummy;
+void takesNonnull(Dummy *_Nonnull);
+
+void test() {
+  Dummy *q = 0;
+  takesNonnull(q); // warn
+}
+
+
+
+
+nullability.NullReturnedFromNonnull
+(ObjC)
+Warns when a null pointer is returned from a function that has 
+_Nonnull return type.
+
+
+typedef struct Dummy { int val; } Dummy;
+
+Dummy *_Nonnull test() {
+  Dummy *p = 0;
+  return p; // warn
+}
+
+
+
+
+nullability.NullableDereferenced
+(ObjC)
+Warns when a nullable pointer is dereferenced.
+
+
+typedef struct Dummy { int val; } Dummy;
+Dummy *_Nullable returnsNullable();
+
+void test() {
+  Dummy *p = returnsNullable();
+  Dummy  = *p; // warn
+}
+
+
+
+
+nullability.NullablePassedToNonnull
+(ObjC)
+Warns when a nullable pointer is passed to a pointer which has a _Nonnull type.
+
+
+typedef struct Dummy { int val; } Dummy;
+Dummy *_Nullable returnsNullable();
+void takesNonnull(Dummy *_Nonnull);
+
+void test() {
+  Dummy *p = returnsNullable();
+  takesNonnull(p); // warn
+}
+
+
+
+
+
+Optin Checkers
+
+
+Name, DescriptionExample
+
+
+
+optin.mpi.MPI-Checker
+(C)
+Checks MPI code
+
+
+void test() {
+  double buf = 0;
+  MPI_Request sendReq1;
+  MPI_Ireduce(MPI_IN_PLACE, , 1, MPI_DOUBLE, MPI_SUM, 
+  0, MPI_COMM_WORLD, );
+} // warn: request 'sendReq1' has no matching wait.
+
+
+void test() {
+  double buf = 0;
+  MPI_Request sendReq;
+  MPI_Isend(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, );
+  MPI_Irecv(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, ); // warn
+  MPI_Isend(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, ); // warn
+  MPI_Wait(, MPI_STATUS_IGNORE);
+}
+
+
+void missingNonBlocking() {
+  int rank = 0;
+  MPI_Comm_rank(MPI_COMM_WORLD, );
+  MPI_Request sendReq1[10][10][10];
+  MPI_Wait([1][7][9], MPI_STATUS_IGNORE); // warn
+}
+
+
+
+
+optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
+(ObjC)
+Check that NSLocalizedString macros include a comment for context.
+
+
+- (void)test {
+  NSString *string = NSLocalizedString(@"LocalizedString", nil); // warn
+  NSString *string2 = NSLocalizedString(@"LocalizedString", @" "); // warn
+  NSString *string3 = NSLocalizedStringWithDefaultValue(
+@"LocalizedString", nil, [[NSBundle alloc] init], nil,@""); // warn
+}
+
+
+
+
+optin.osx.cocoa.localizability.NonLocalizedStringChecker
+(ObjC)
+Warns about uses of non-localized NSStrings passed to UI methods 
+expecting localized NSStrings
+
+
+- (void)test {
+  UILabel *testLabel = [[UILabel alloc] init];
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");
+
+  if (random()) { 
+bar = @"Unlocalized string";
+  }
+
+  [testLabel setText:bar]; // warn
+}
+
+
+
+
+
 OS X Checkers
 
 
@@ -466,6 +630,37 @@
 
 
 
+osx.NumberObjectConversion
+(C, C++, ObjC)
+Check for erroneous conversions of objects representing numbers 
+into numbers
+
+
+typedef const struct __CFNumber *CFNumberRef;
+void takes_int(int);
+
+void test(CFNumberRef p) {
+#ifdef PEDANTIC
+  if (p) {} // warn
+  if (!p) {} // warn
+  p ? 1 : 2; // warn
+  if (p == 0) {} // warn
+#else
+  if (p) {} // no-warning
+  if (!p) {} // no-warning
+  p ? 1 : 2; // no-warning
+  if 

[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-06-16 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik added inline comments.



Comment at: clang-tidy/misc/UndelegatedCopyOfBaseClassesCheck.cpp:92
+  // Loop until the beginning of the initialization list.
+  while (!Tok.is(tok::r_paren))
+Lex.LexFromRawLexer(Tok);

aaron.ballman wrote:
> szdominik wrote:
> > aaron.ballman wrote:
> > > This doesn't balance tokens. What about:
> > > ```
> > > struct S {
> > >  /* ... */
> > > };
> > > 
> > > struct T : S {
> > >   T(const T ) : S((1 + 2), O) {}
> > > };
> > > ```
> > The loop search only the first right paren in the line, which is the end of 
> > parameter list ( "...&0**)**" ), so, as I see, it doesn't interesting what 
> > happens after the colon.
> Let me try again. :-)
> ```
> struct S {
>  /* ... */
> };
> 
> struct T : S {
>   T(const T , int = (1 + 2)) : S((1 + 2), O) {}
> };
> ```
Ah, you're right. I'll figure out something... :)


https://reviews.llvm.org/D33722



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


[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-06-16 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik added inline comments.



Comment at: clang-tidy/misc/UndelegatedCopyOfBaseClassesCheck.cpp:92
+  // Loop until the beginning of the initialization list.
+  while (!Tok.is(tok::r_paren))
+Lex.LexFromRawLexer(Tok);

aaron.ballman wrote:
> This doesn't balance tokens. What about:
> ```
> struct S {
>  /* ... */
> };
> 
> struct T : S {
>   T(const T ) : S((1 + 2), O) {}
> };
> ```
The loop search only the first right paren in the line, which is the end of 
parameter list ( "...&0**)**" ), so, as I see, it doesn't interesting what 
happens after the colon.


https://reviews.llvm.org/D33722



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


[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-06-16 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik updated this revision to Diff 102807.
szdominik marked 9 inline comments as done.
szdominik added a comment.

Rename check.
Hoisted matcher, changed warning message & nits.


https://reviews.llvm.org/D33722

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/CopyConstructorInitCheck.cpp
  clang-tidy/misc/CopyConstructorInitCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-copy-constructor-init.rst
  test/clang-tidy/misc-copy-constructor-init.cpp

Index: test/clang-tidy/misc-copy-constructor-init.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-copy-constructor-init.cpp
@@ -0,0 +1,96 @@
+// RUN: %check_clang_tidy %s misc-copy-constructor-init %t
+
+class Copyable {
+	public:
+	Copyable() = default;
+	Copyable(const Copyable&) = default;
+};
+class X : public Copyable {
+	X(const X& other) : Copyable(other) {}
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class Copyable2 {
+	public:
+	Copyable2() = default;
+	Copyable2(const Copyable2&) = default;
+};
+class X2 : public Copyable2 {
+	X2(const X2& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable2(other)
+};
+
+class X3 : public Copyable, public Copyable2 {
+	X3(const X3& other): Copyable(other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: Copyable2(other), 
+};
+
+class X4 : public Copyable {
+	X4(const X4& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: other
+};
+
+class Copyable3 : public Copyable {
+	public:
+	Copyable3() = default;
+	Copyable3(const Copyable3&) = default;
+};
+class X5 : public Copyable3 {
+	X5(const X5& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable3(other)
+};
+
+class X6 : public Copyable2, public Copyable3 {
+	X6(const X6& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable2(other), Copyable3(other)
+};
+
+class X7 : public Copyable, public Copyable2 {
+	X7(const X7& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: other
+	// CHECK-MESSAGES: :[[@LINE-3]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: Copyable2(other), 
+};
+
+template 
+class Copyable4 {
+	public:
+	Copyable4() = default;
+	Copyable4(const Copyable4&) = default;
+};
+
+class X8 : public Copyable4 {
+	X8(const X8& other): Copyable4(other) {};
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class X9 : public Copyable4 {
+	X9(const X9& other): Copyable4() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: other
+};
+
+class X10 : public Copyable4 {
+	X10(const X10& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable4(other)
+};
+
+template 
+class Copyable5 {
+	public:
+	Copyable5() = default;
+	Copyable5(const Copyable5&) = default;
+};
+
+class X11 : public Copyable5 {
+	X11(const X11& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: calling an inherited constructor other than the copy constructor [misc-copy-constructor-init]
+	// CHECK-FIXES: : Copyable5(other)
+};
Index: docs/clang-tidy/checks/misc-copy-constructor-init.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-copy-constructor-init.rst
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - misc-copy-constructor-init
+
+misc-copy-constructor-init
+=
+
+Finds copy constructors where the constructor don't call 
+the constructor of the base class.
+
+.. code-block:: c++
+
+class Copyable {
+public:
+Copyable() = default;
+Copyable(const Copyable&) = default;
+};
+class X2 : public Copyable {
+X2(const X2& other) {}; // Copyable(other) is missing
+};
+
+Also finds copy constructors where the constructor of 
+the base class don't have parameter. 
+
+.. code-block:: c++
+
+class X4 : public Copyable {
+X4(const X4& other): Copyable() {}; // other 

[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-06-15 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik marked 3 inline comments as done.
szdominik added inline comments.



Comment at: www/analyzer/alpha_checks.html:91
+(C, C++)
+Check for logical errors for function calls and Objective-C message 
+expressions (e.g., uninitialized arguments, null function pointers, 

zaks.anna wrote:
> for function calls -> in function calls?
> After briefly looking into this, the checker only reports the use of 
> uninitialized arguments in calls, not the other issues (like null function 
> pointers). Could you double check this?
As I see here
https://github.com/llvm-mirror/clang/blob/master/lib/StaticAnalyzer/Checkers/CallAndMessageChecker.cpp#L341
 
there are checks for null pointers too. 


https://reviews.llvm.org/D33645



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


[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-06-15 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik updated this revision to Diff 102650.
szdominik added a comment.

Delete modeling checkers (unix.StdCLibraryFunctions, cplusplus.SelfAssignment).
Delete unix.MallocWithAnnotations.


https://reviews.llvm.org/D33645

Files:
  www/analyzer/alpha_checks.html
  www/analyzer/available_checks.html
  www/analyzer/implicit_checks.html

Index: www/analyzer/implicit_checks.html
===
--- www/analyzer/implicit_checks.html
+++ www/analyzer/implicit_checks.html
@@ -27,7 +27,7 @@
 OS X Implicit Checkers
 
 
-
+
 Core Implicit Checkers
 
 
@@ -124,7 +124,7 @@
 
 
 
-
+
 OS X Implicit Checkers
 
 
Index: www/analyzer/available_checks.html
===
--- www/analyzer/available_checks.html
+++ www/analyzer/available_checks.html
@@ -38,12 +38,14 @@
 Core Checkers model core language features and perform general-purpose checks such as division by zero, null pointer dereference, usage of uninitialized values, etc.
 C++ Checkers perform C++-specific checks
 Dead Code Checkers check for unused code
+Nullability Checkers 
+Optin Checkers 
 OS X Checkers perform Objective-C-specific checks and check the use of Apple's SDKs (OS X and iOS)
 Security Checkers check for insecure API usage and perform checks based on the CERT Secure Coding Standards
 Unix Checkers check the use of Unix and POSIX APIs
 
 
-
+
 Core Checkers
 
 
@@ -360,7 +362,7 @@
 
 
 
-
+
 C++ Checkers
 
 
@@ -421,9 +423,21 @@
 }
 
 
+
+cplusplus.NewDeleteLeaks
+(C++)
+Check for memory leaks. Traces memory managed by new/
+delete.
+
+
+void test() {
+  int *p = new int;
+} // warn
+
+
 
 
-
+
 Dead Code Checkers
 
 
@@ -444,7 +458,157 @@
 
 
 
-
+
+Nullability Checkers
+
+
+Name, DescriptionExample
+
+
+
+nullability.NullPassedToNonnull
+(ObjC)
+Warns when a null pointer is passed to a pointer which has a 
+_Nonnull type.
+
+
+typedef struct Dummy { int val; } Dummy;
+void takesNonnull(Dummy *_Nonnull);
+
+void test() {
+  Dummy *q = 0;
+  takesNonnull(q); // warn
+}
+
+
+
+
+nullability.NullReturnedFromNonnull
+(ObjC)
+Warns when a null pointer is returned from a function that has 
+_Nonnull return type.
+
+
+typedef struct Dummy { int val; } Dummy;
+
+Dummy *_Nonnull test() {
+  Dummy *p = 0;
+  return p; // warn
+}
+
+
+
+
+nullability.NullableDereferenced
+(ObjC)
+Warns when a nullable pointer is dereferenced.
+
+
+typedef struct Dummy { int val; } Dummy;
+Dummy *_Nullable returnsNullable();
+
+void test() {
+  Dummy *p = returnsNullable();
+  Dummy  = *p; // warn
+}
+
+
+
+
+nullability.NullablePassedToNonnull
+(ObjC)
+Warns when a nullable pointer is passed to a pointer which has a _Nonnull type.
+
+
+typedef struct Dummy { int val; } Dummy;
+Dummy *_Nullable returnsNullable();
+void takesNonnull(Dummy *_Nonnull);
+
+void test() {
+  Dummy *p = returnsNullable();
+  takesNonnull(p); // warn
+}
+
+
+
+
+
+Optin Checkers
+
+
+Name, DescriptionExample
+
+
+
+optin.mpi.MPI-Checker
+(C)
+Checks MPI code
+
+
+void test() {
+  double buf = 0;
+  MPI_Request sendReq1;
+  MPI_Ireduce(MPI_IN_PLACE, , 1, MPI_DOUBLE, MPI_SUM, 
+  0, MPI_COMM_WORLD, );
+} // warn: request 'sendReq1' has no matching wait.
+
+
+void test() {
+  double buf = 0;
+  MPI_Request sendReq;
+  MPI_Isend(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, );
+  MPI_Irecv(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, ); // warn
+  MPI_Isend(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, ); // warn
+  MPI_Wait(, MPI_STATUS_IGNORE);
+}
+
+
+void missingNonBlocking() {
+  int rank = 0;
+  MPI_Comm_rank(MPI_COMM_WORLD, );
+  MPI_Request sendReq1[10][10][10];
+  MPI_Wait([1][7][9], MPI_STATUS_IGNORE); // warn
+}
+
+
+
+
+optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
+(ObjC)
+Check that NSLocalizedString macros include a comment for context.
+
+
+- (void)test {
+  NSString *string = NSLocalizedString(@"LocalizedString", nil); // warn
+  NSString *string2 = NSLocalizedString(@"LocalizedString", @" "); // warn
+  NSString *string3 = NSLocalizedStringWithDefaultValue(
+@"LocalizedString", nil, [[NSBundle alloc] init], nil,@""); // warn
+}
+
+
+
+
+optin.osx.cocoa.localizability.NonLocalizedStringChecker
+(ObjC)
+Warns about uses of non-localized NSStrings passed to UI methods 
+expecting localized NSStrings
+
+
+- (void)test {
+  UILabel *testLabel = [[UILabel alloc] init];
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");
+
+  if (random()) { 
+bar = @"Unlocalized string";
+  }
+
+  [testLabel setText:bar]; // warn
+}
+
+
+
+
+
 OS X Checkers
 
 
@@ -466,6 +630,37 @@
 
 
 
+osx.NumberObjectConversion
+(C, C++, ObjC)
+Check for erroneous conversions of objects representing numbers 
+into numbers
+
+
+typedef const struct __CFNumber *CFNumberRef;
+void takes_int(int);
+
+void test(CFNumberRef p) {
+#ifdef PEDANTIC
+  if (p) {} // warn
+  if (!p) {} // warn
+  p ? 1 : 2; // warn
+  if (p == 0) {} // warn
+#else
+  if (p) {} // no-warning
+  if (!p) {} // no-warning
+  p ? 1 

[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-06-10 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik marked 2 inline comments as done.
szdominik added a comment.

Warnings of the check's run on llvm/clang codebase.

F3426875: undelegated-copy-of-base-classes-clangrun.txt 



https://reviews.llvm.org/D33722



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


[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-05-31 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik updated this revision to Diff 100892.
szdominik added a comment.

Update with fixed docs.


https://reviews.llvm.org/D33722

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/UndelegatedCopyOfBaseClassesCheck.cpp
  clang-tidy/misc/UndelegatedCopyOfBaseClassesCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-undelegated-copy-of-base-classes.rst
  test/clang-tidy/misc-undelegated-copy-of-base-classes.cpp

Index: test/clang-tidy/misc-undelegated-copy-of-base-classes.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-undelegated-copy-of-base-classes.cpp
@@ -0,0 +1,96 @@
+// RUN: %check_clang_tidy %s misc-undelegated-copy-of-base-classes %t
+
+class Copyable {
+	public:
+	Copyable() = default;
+	Copyable(const Copyable&) = default;
+};
+class X : public Copyable {
+	X(const X& other) : Copyable(other) {}
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class Copyable2 {
+	public:
+	Copyable2() = default;
+	Copyable2(const Copyable2&) = default;
+};
+class X2 : public Copyable2 {
+	X2(const X2& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable2(other)
+};
+
+class X3 : public Copyable, public Copyable2 {
+	X3(const X3& other): Copyable(other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: Copyable2(other), 
+};
+
+class X4 : public Copyable {
+	X4(const X4& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: Missing parameter in the base initializer! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: other
+};
+
+class Copyable3 : public Copyable {
+	public:
+	Copyable3() = default;
+	Copyable3(const Copyable3&) = default;
+};
+class X5 : public Copyable3 {
+	X5(const X5& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable3(other)
+};
+
+class X6 : public Copyable2, public Copyable3 {
+	X6(const X6& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable2(other), Copyable3(other)
+};
+
+class X7 : public Copyable, public Copyable2 {
+	X7(const X7& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: Missing parameter in the base initializer! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: other
+	// CHECK-MESSAGES: :[[@LINE-3]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: Copyable2(other), 
+};
+
+template 
+class Copyable4 {
+	public:
+	Copyable4() = default;
+	Copyable4(const Copyable4&) = default;
+};
+
+class X8 : public Copyable4 {
+	X8(const X8& other): Copyable4(other) {};
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class X9 : public Copyable4 {
+	X9(const X9& other): Copyable4() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: Missing parameter in the base initializer! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: other
+};
+
+class X10 : public Copyable4 {
+	X10(const X10& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable4(other)
+};
+
+template 
+class Copyable5 {
+	public:
+	Copyable5() = default;
+	Copyable5(const Copyable5&) = default;
+};
+
+class X11 : public Copyable5 {
+	X11(const X11& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable5(other)
+};
Index: docs/clang-tidy/checks/misc-undelegated-copy-of-base-classes.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-undelegated-copy-of-base-classes.rst
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - misc-undelegated-copy-of-base-classes
+
+misc-undelegated-copy-of-base-classes
+=
+
+Finds copy constructors where the constructor don't call 
+the constructor of the base class.
+
+.. code-block:: c++
+
+class Copyable {
+public:
+Copyable() = default;
+Copyable(const Copyable&) = default;
+};
+class X2 : public Copyable {
+X2(const X2& other) {}; // Copyable(other) is missing
+};
+
+Also finds copy constructors where the 

[PATCH] D33722: [clang-tidy] Add checker for undelegated copy of base classes

2017-05-31 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik created this revision.
Herald added a subscriber: mgorny.

Finds copy constructors where the constructor don't call 
the constructor of the base class.

  class X : public Copyable {
  X(const X& other) {}; // Copyable(other) is missing
  };

Also finds copy constructors where the base initializer 
don't have parameter.


https://reviews.llvm.org/D33722

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/UndelegatedCopyOfBaseClassesCheck.cpp
  clang-tidy/misc/UndelegatedCopyOfBaseClassesCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-undelegated-copy-of-base-classes.rst
  test/clang-tidy/misc-undelegated-copy-of-base-classes.cpp

Index: test/clang-tidy/misc-undelegated-copy-of-base-classes.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-undelegated-copy-of-base-classes.cpp
@@ -0,0 +1,96 @@
+// RUN: %check_clang_tidy %s misc-undelegated-copy-of-base-classes %t
+
+class Copyable {
+	public:
+	Copyable() = default;
+	Copyable(const Copyable&) = default;
+};
+class X : public Copyable {
+	X(const X& other) : Copyable(other) {}
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class Copyable2 {
+	public:
+	Copyable2() = default;
+	Copyable2(const Copyable2&) = default;
+};
+class X2 : public Copyable2 {
+	X2(const X2& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable2(other)
+};
+
+class X3 : public Copyable, public Copyable2 {
+	X3(const X3& other): Copyable(other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: Copyable2(other), 
+};
+
+class X4 : public Copyable {
+	X4(const X4& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: Missing parameter in the base initializer! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: other
+};
+
+class Copyable3 : public Copyable {
+	public:
+	Copyable3() = default;
+	Copyable3(const Copyable3&) = default;
+};
+class X5 : public Copyable3 {
+	X5(const X5& other) {};
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable3(other)
+};
+
+class X6 : public Copyable2, public Copyable3 {
+	X6(const X6& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable2(other), Copyable3(other)
+};
+
+class X7 : public Copyable, public Copyable2 {
+	X7(const X7& other): Copyable() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:32: warning: Missing parameter in the base initializer! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: other
+	// CHECK-MESSAGES: :[[@LINE-3]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: Copyable2(other), 
+};
+
+template 
+class Copyable4 {
+	public:
+	Copyable4() = default;
+	Copyable4(const Copyable4&) = default;
+};
+
+class X8 : public Copyable4 {
+	X8(const X8& other): Copyable4(other) {};
+	//Good code: the copy ctor call the ctor of the base class.
+};
+
+class X9 : public Copyable4 {
+	X9(const X9& other): Copyable4() {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:37: warning: Missing parameter in the base initializer! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: other
+};
+
+class X10 : public Copyable4 {
+	X10(const X10& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable4(other)
+};
+
+template 
+class Copyable5 {
+	public:
+	Copyable5() = default;
+	Copyable5(const Copyable5&) = default;
+};
+
+class X11 : public Copyable5 {
+	X11(const X11& other) {};
+	// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: Copy constructor should call the copy constructor of all copyable base class! [misc-undelegated-copy-of-base-classes]
+	// CHECK-FIXES: : Copyable5(other)
+};
\ No newline at end of file
Index: docs/clang-tidy/checks/misc-undelegated-copy-of-base-classes.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-undelegated-copy-of-base-classes.rst
@@ -0,0 +1,30 @@
+.. title:: clang-tidy - misc-undelegated-copy-of-base-classes
+
+misc-undelegated-copy-of-base-classes
+=
+
+Finds copy constructors where the constructor don't call 
+the constructor of the base class.
+
+.. code-block:: c++
+
+class Copyable {
+

[PATCH] D33645: [analyzer] Add missing documentation for static analyzer checkers

2017-05-29 Thread Dominik Szabó via Phabricator via cfe-commits
szdominik created this revision.

Some checks did not have documentation in the www/analyzer/ folder, and also 
some alpha checks became non-alpha.


https://reviews.llvm.org/D33645

Files:
  www/analyzer/alpha_checks.html
  www/analyzer/available_checks.html
  www/analyzer/implicit_checks.html

Index: www/analyzer/implicit_checks.html
===
--- www/analyzer/implicit_checks.html
+++ www/analyzer/implicit_checks.html
@@ -27,7 +27,7 @@
 OS X Implicit Checkers
 
 
-
+
 Core Implicit Checkers
 
 
@@ -124,7 +124,7 @@
 
 
 
-
+
 OS X Implicit Checkers
 
 
Index: www/analyzer/available_checks.html
===
--- www/analyzer/available_checks.html
+++ www/analyzer/available_checks.html
@@ -38,12 +38,14 @@
 Core Checkers model core language features and perform general-purpose checks such as division by zero, null pointer dereference, usage of uninitialized values, etc.
 C++ Checkers perform C++-specific checks
 Dead Code Checkers check for unused code
+Nullability Checkers 
+Optin Checkers 
 OS X Checkers perform Objective-C-specific checks and check the use of Apple's SDKs (OS X and iOS)
 Security Checkers check for insecure API usage and perform checks based on the CERT Secure Coding Standards
 Unix Checkers check the use of Unix and POSIX APIs
 
 
-
+
 Core Checkers
 
 
@@ -360,7 +362,7 @@
 
 
 
-
+
 C++ Checkers
 
 
@@ -421,9 +423,29 @@
 }
 
 
+
+cplusplus.NewDeleteLeaks
+(C++)
+Check for memory leaks. Traces memory managed by new/
+delete.
+
+
+void test() {
+  int *p = new int;
+} // warn
+
+
+
+
+cplusplus.SelfAssignment
+(C++)
+Checks C++ copy and move assignment operators for self assignment,
+but itself doesn't warn. It's for modeling self assignment -
+other checkers could find errors.
+
 
 
-
+
 Dead Code Checkers
 
 
@@ -444,7 +466,157 @@
 
 
 
-
+
+Nullability Checkers
+
+
+Name, DescriptionExample
+
+
+
+nullability.NullPassedToNonnull
+(ObjC)
+Warns when a null pointer is passed to a pointer which has a 
+_Nonnull type.
+
+
+typedef struct Dummy { int val; } Dummy;
+void takesNonnull(Dummy *_Nonnull);
+
+void test() {
+  Dummy *q = 0;
+  takesNonnull(q); // warn
+}
+
+
+
+
+nullability.NullReturnedFromNonnull
+(ObjC)
+Warns when a null pointer is returned from a function that has 
+_Nonnull return type.
+
+
+typedef struct Dummy { int val; } Dummy;
+
+Dummy *_Nonnull test() {
+  Dummy *p = 0;
+  return p; // warn
+}
+
+
+
+
+nullability.NullableDereferenced
+(ObjC)
+Warns when a nullable pointer is dereferenced.
+
+
+typedef struct Dummy { int val; } Dummy;
+Dummy *_Nullable returnsNullable();
+
+void test() {
+  Dummy *p = returnsNullable();
+  Dummy  = *p; // warn
+}
+
+
+
+
+nullability.NullablePassedToNonnull
+(ObjC)
+Warns when a nullable pointer is passed to a pointer which has a _Nonnull type.
+
+
+typedef struct Dummy { int val; } Dummy;
+Dummy *_Nullable returnsNullable();
+void takesNonnull(Dummy *_Nonnull);
+
+void test() {
+  Dummy *p = returnsNullable();
+  takesNonnull(p); // warn
+}
+
+
+
+
+
+Optin Checkers
+
+
+Name, DescriptionExample
+
+
+
+optin.mpi.MPI-Checker
+(C)
+Checks MPI code
+
+
+void test() {
+  double buf = 0;
+  MPI_Request sendReq1;
+  MPI_Ireduce(MPI_IN_PLACE, , 1, MPI_DOUBLE, MPI_SUM, 
+  0, MPI_COMM_WORLD, );
+} // warn: request 'sendReq1' has no matching wait.
+
+
+void test() {
+  double buf = 0;
+  MPI_Request sendReq;
+  MPI_Isend(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, );
+  MPI_Irecv(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, ); // warn
+  MPI_Isend(, 1, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, ); // warn
+  MPI_Wait(, MPI_STATUS_IGNORE);
+}
+
+
+void missingNonBlocking() {
+  int rank = 0;
+  MPI_Comm_rank(MPI_COMM_WORLD, );
+  MPI_Request sendReq1[10][10][10];
+  MPI_Wait([1][7][9], MPI_STATUS_IGNORE); // warn
+}
+
+
+
+
+optin.osx.cocoa.localizability.EmptyLocalizationContextChecker
+(ObjC)
+Check that NSLocalizedString macros include a comment for context.
+
+
+- (void)test {
+  NSString *string = NSLocalizedString(@"LocalizedString", nil); // warn
+  NSString *string2 = NSLocalizedString(@"LocalizedString", @" "); // warn
+  NSString *string3 = NSLocalizedStringWithDefaultValue(
+@"LocalizedString", nil, [[NSBundle alloc] init], nil,@""); // warn
+}
+
+
+
+
+optin.osx.cocoa.localizability.NonLocalizedStringChecker
+(ObjC)
+Warns about uses of non-localized NSStrings passed to UI methods 
+expecting localized NSStrings
+
+
+- (void)test {
+  UILabel *testLabel = [[UILabel alloc] init];
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");
+
+  if (random()) { 
+bar = @"Unlocalized string";
+  }
+
+  [testLabel setText:bar]; // warn
+}
+
+
+
+
+
 OS X Checkers
 
 
@@ -466,6 +638,37 @@
 
 
 
+osx.NumberObjectConversion
+(C, C++, ObjC)
+Check for erroneous conversions of objects representing numbers 
+into numbers
+
+
+typedef const struct __CFNumber *CFNumberRef;
+void takes_int(int);
+
+void test(CFNumberRef p) {
+#ifdef PEDANTIC
+