[clang-tools-extra] r222981 - [clang-tidy] google-explicit-constructor: don't match in template instantiations
Alexander Kornienko
alexfh at google.com
Sun Nov 30 11:41:41 PST 2014
Author: alexfh
Date: Sun Nov 30 13:41:41 2014
New Revision: 222981
URL: http://llvm.org/viewvc/llvm-project?rev=222981&view=rev
Log:
[clang-tidy] google-explicit-constructor: don't match in template instantiations
This helps avoiding false positives related to the recently added
std::initializer_list<> handling.
Modified:
clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/google-explicit-constructor.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=222981&r1=222980&r2=222981&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp Sun Nov 30 13:41:41 2014
@@ -19,7 +19,8 @@ namespace clang {
namespace tidy {
void ExplicitConstructorCheck::registerMatchers(MatchFinder *Finder) {
- Finder->addMatcher(constructorDecl().bind("ctor"), this);
+ Finder->addMatcher(constructorDecl(unless(isInstantiated())).bind("ctor"),
+ this);
}
// Looks for the token matching the predicate and returns the range of the found
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=222981&r1=222980&r2=222981&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 Sun Nov 30 13:41:41 2014
@@ -78,3 +78,21 @@ struct C {
C(const initializer_list<unsigned> &list2) {}
C(initializer_list<unsigned> &&list3) {}
};
+
+struct D {
+ template <typename T>
+ explicit D(T t) {}
+};
+
+template <typename T>
+struct E {
+ explicit E(T t) {}
+ template <typename U>
+ explicit E(U u) {}
+};
+
+void f(std::initializer_list<int> list) {
+ D d(list);
+ E<decltype(list)> e(list);
+ E<int> e2(list);
+}
More information about the cfe-commits
mailing list