[clang-tidy] google-explicit-constructor: ignore template instantiations

llvm-svn: 290753
This commit is contained in:
Alexander Kornienko 2016-12-30 13:25:03 +00:00
parent 03226c5e06
commit 56d0806644
2 changed files with 36 additions and 2 deletions

View File

@ -27,8 +27,10 @@ void ExplicitConstructorCheck::registerMatchers(MatchFinder *Finder) {
Finder->addMatcher(cxxConstructorDecl(unless(isInstantiated())).bind("ctor"),
this);
Finder->addMatcher(
cxxConversionDecl(unless(isExplicit()), // Already marked explicit.
unless(isImplicit())) // Compiler-generated.
cxxConversionDecl(unless(anyOf(isExplicit(), // Already marked explicit.
isImplicit(), // Compiler-generated.
isInstantiated())))
.bind("conversion"),
this);
}

View File

@ -138,3 +138,35 @@ void f(std::initializer_list<int> list) {
E<decltype(list)> e(list);
E<int> e2(list);
}
template <typename T>
struct F {};
template<typename T>
struct G {
operator bool() const;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator bool' must be marked
// CHECK-FIXES: {{^}} explicit operator bool() const;
operator F<T>() const;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator F<type-parameter-0-0>' must be marked
// CHECK-FIXES: {{^}} explicit operator F<T>() const;
template<typename U>
operator F<U>*() const;
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator F<type-parameter-1-0> *' must be marked
// CHECK-FIXES: {{^}} explicit operator F<U>*() const;
};
void f2() {
G<int> a;
(void)(F<int>)a;
if (a) {}
(void)(F<int>*)a;
(void)(F<int*>*)a;
G<double> b;
(void)(F<double>)b;
if (b) {}
(void)(F<double>*)b;
(void)(F<double*>*)b;
}