diff options
| author | Alexander Kornienko <alexfh@google.com> | 2016-12-30 13:25:03 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2016-12-30 13:25:03 +0000 |
| commit | 56d0806644f37abc26d5ea9abf91114e52cd3fa7 (patch) | |
| tree | d345574615cbb17d75ae0291cb36065f4934e082 | |
| parent | 03226c5e0632268ffc778414ecb421fccead4367 (diff) | |
| download | bcm5719-llvm-56d0806644f37abc26d5ea9abf91114e52cd3fa7.tar.gz bcm5719-llvm-56d0806644f37abc26d5ea9abf91114e52cd3fa7.zip | |
[clang-tidy] google-explicit-constructor: ignore template instantiations
llvm-svn: 290753
| -rw-r--r-- | clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp | 6 | ||||
| -rw-r--r-- | clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp | 32 |
2 files changed, 36 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp index 1257d100d3d..1605626d142 100644 --- a/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp +++ b/clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp @@ -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); } diff --git a/clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp b/clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp index 6cc3435b9b8..aac6ab62bd2 100644 --- a/clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp +++ b/clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp @@ -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; + +} |

