Author: alexfh Date: Fri Nov 27 20:25:02 2015 New Revision: 254216 URL: http://llvm.org/viewvc/llvm-project?rev=254216&view=rev Log: [clang-tidy] google-explicit-constructor: improve the warning message
Also switch some more tests to %check_clang_tidy. Modified: clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp clang-tools-extra/trunk/test/clang-tidy/line-filter.cpp clang-tools-extra/trunk/test/clang-tidy/macros.cpp clang-tools-extra/trunk/test/clang-tidy/nolint.cpp Modified: clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp?rev=254216&r1=254215&r2=254216&view=diff ============================================================================== --- clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp (original) +++ clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp Fri Nov 27 20:25:02 2015 @@ -119,9 +119,11 @@ void ExplicitConstructorCheck::check(con bool SingleArgument = Ctor->getNumParams() == 1 && !Ctor->getParamDecl(0)->isParameterPack(); SourceLocation Loc = Ctor->getLocation(); - diag(Loc, SingleArgument ? "single-argument constructors must be explicit" - : "constructors that are callable with a single " - "argument must be marked explicit") + diag(Loc, + "%0 must be marked explicit to avoid unintentional implicit conversions") + << (SingleArgument + ? "single-argument constructors" + : "constructors that are callable with a single argument") << FixItHint::CreateInsertion(Loc, "explicit "); } Modified: clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp?rev=254216&r1=254215&r2=254216&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp Fri Nov 27 20:25:02 2015 @@ -1,10 +1,8 @@ -// RUN: clang-tidy -checks='-*,google-explicit-constructor' %s -- | FileCheck %s +// RUN: %check_clang_tidy %s google-explicit-constructor %t template<typename T> struct A { A(T); }; -// CHECK: :[[@LINE-1]]:12: warning: single-argument constructors must be explicit [google-explicit-constructor] -// CHECK-NOT: warning: - +// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit void f() { A<int> a(0); Modified: clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp?rev=254216&r1=254215&r2=254216&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp Fri Nov 27 20:25:02 2015 @@ -11,8 +11,8 @@ // CHECK3: :[[@LINE+1]]:9: warning: implicit conversion from 'double' to 'int' changes value int a = 1.5; -// CHECK2: :[[@LINE+2]]:11: warning: single-argument constructors must be explicit [google-explicit-constructor] -// CHECK3: :[[@LINE+1]]:11: warning: single-argument constructors must be explicit [google-explicit-constructor] +// CHECK2: :[[@LINE+2]]:11: warning: single-argument constructors must be marked explicit +// CHECK3: :[[@LINE+1]]:11: warning: single-argument constructors must be marked explicit class A { A(int) {} }; #define MACRO_FROM_COMMAND_LINE Modified: clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp?rev=254216&r1=254215&r2=254216&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp Fri Nov 27 20:25:02 2015 @@ -8,7 +8,7 @@ #include "header1.h" // CHECK-NOT: warning: -// CHECK2: header1.h:1:12: warning: single-argument constructors must be explicit [google-explicit-constructor] +// CHECK2: header1.h:1:12: warning: single-argument constructors must be marked explicit // CHECK3-NOT: warning: // CHECK4: header1.h:1:12: warning: single-argument constructors Modified: clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp?rev=254216&r1=254215&r2=254216&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.cpp Fri Nov 27 20:25:02 2015 @@ -44,11 +44,11 @@ struct A { // CHECK-FIXES: {{^ }}A(const A& a) {} A(int x1) {} - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: single-argument constructors must be explicit [google-explicit-constructor] + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor] // CHECK-FIXES: {{^ }}explicit A(int x1) {} A(double x2, double y = 3.14) {} - // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructors that are callable with a single argument must be marked explicit [google-explicit-constructor] + // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructors that are callable with a single argument must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor] // CHECK-FIXES: {{^ }}explicit A(double x2, double y = 3.14) {} template <typename... T> Modified: clang-tools-extra/trunk/test/clang-tidy/line-filter.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/line-filter.cpp?rev=254216&r1=254215&r2=254216&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/line-filter.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/line-filter.cpp Fri Nov 27 20:25:02 2015 @@ -2,7 +2,7 @@ #include "header1.h" // CHECK-NOT: header1.h:{{.*}} warning -// CHECK: header1.h:1:12: warning: single-argument constructors must be explicit [google-explicit-constructor] +// CHECK: header1.h:1:12: warning: single-argument constructors must be marked explicit // CHECK: header1.h:2:12: warning: single-argument constructors {{.*}} // CHECK-NOT: header1.h:{{.*}} warning Modified: clang-tools-extra/trunk/test/clang-tidy/macros.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/macros.cpp?rev=254216&r1=254215&r2=254216&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/macros.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/macros.cpp Fri Nov 27 20:25:02 2015 @@ -3,5 +3,5 @@ #define Q(name) class name { name(int i); } Q(A); -// CHECK: :[[@LINE-1]]:3: warning: single-argument constructors must be explicit [google-explicit-constructor] +// CHECK: :[[@LINE-1]]:3: warning: single-argument constructors must be marked explicit // CHECK: :3:30: note: expanded from macro 'Q' Modified: clang-tools-extra/trunk/test/clang-tidy/nolint.cpp URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/nolint.cpp?rev=254216&r1=254215&r2=254216&view=diff ============================================================================== --- clang-tools-extra/trunk/test/clang-tidy/nolint.cpp (original) +++ clang-tools-extra/trunk/test/clang-tidy/nolint.cpp Fri Nov 27 20:25:02 2015 @@ -1,11 +1,9 @@ -// RUN: clang-tidy -checks='-*,google-explicit-constructor' %s -- 2>&1 | FileCheck %s +// RUN: %check_clang_tidy %s google-explicit-constructor %t class A { A(int i); }; -// CHECK: :[[@LINE-1]]:11: warning: single-argument constructors must be explicit [google-explicit-constructor] +// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: single-argument constructors must be marked explicit class B { B(int i); }; // NOLINT -// CHECK-NOT: :[[@LINE-1]]:11: warning: single-argument constructors must be explicit [google-explicit-constructor] class C { C(int i); }; // NOLINT(we-dont-care-about-categories-yet) -// CHECK-NOT: :[[@LINE-1]]:11: warning: single-argument constructors must be explicit [google-explicit-constructor] -// CHECK: Suppressed 2 warnings (2 NOLINT) +// CHECK-MESSAGES: Suppressed 2 warnings (2 NOLINT) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits