[clang-tidy] Fix google-explicit-constructor issue with out-of-line conversions
authorAlexander Kornienko <alexfh@google.com>
Tue, 18 Apr 2017 17:26:00 +0000 (17:26 +0000)
committerAlexander Kornienko <alexfh@google.com>
Tue, 18 Apr 2017 17:26:00 +0000 (17:26 +0000)
llvm-svn: 300569

clang-tools-extra/clang-tidy/google/ExplicitConstructorCheck.cpp
clang-tools-extra/test/clang-tidy/google-explicit-constructor.cpp

index df21d46..a03fb56 100644 (file)
@@ -91,6 +91,8 @@ void ExplicitConstructorCheck::check(const MatchFinder::MatchResult &Result) {
 
   if (const auto *Conversion =
       Result.Nodes.getNodeAs<CXXConversionDecl>("conversion")) {
+    if (Conversion->isOutOfLine())
+      return;
     SourceLocation Loc = Conversion->getLocation();
     // Ignore all macros until we learn to ignore specific ones (e.g. used in
     // gmock to define matchers).
index cfd4282..921237a 100644 (file)
@@ -46,9 +46,9 @@ struct A {
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: copy constructor should not be declared explicit [google-explicit-constructor]
   // CHECK-FIXES: {{^  }}A(const A& a) {}
 
-  A(int x1) {}
+  A(int x1);
   // 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) {}
+  // 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 to avoid unintentional implicit conversions [google-explicit-constructor]
@@ -60,6 +60,8 @@ struct A {
   // CHECK-FIXES: {{^  }}explicit A(T&&... args);
 };
 
+inline A::A(int x1) {}
+
 struct B {
   B(std::initializer_list<int> list1) {}
   B(const std::initializer_list<unsigned> &list2) {}
@@ -69,6 +71,10 @@ struct B {
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator bool' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
   // CHECK-FIXES: {{^  }}explicit operator bool() const { return true; }
 
+  operator double() const;
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: 'operator double' must be marked explicit to avoid unintentional implicit conversions [google-explicit-constructor]
+  // CHECK-FIXES: {{^  }}explicit operator double() const;
+
   explicit B(::std::initializer_list<double> list4) {}
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: initializer-list constructor should not be declared explicit [google-explicit-constructor]
   // CHECK-FIXES: {{^  }}B(::std::initializer_list<double> list4) {}
@@ -82,6 +88,8 @@ struct B {
   // CHECK-FIXES: {{^  }}B(::std::initializer_list<char> &&list6) {}
 };
 
+inline B::operator double() const { return 0.0; }
+
 struct StructWithFnPointer {
   void (*f)();
 } struct_with_fn_pointer = {[] {}};