[clang-tidy] Fix google-explicit-constructor issue with out-of-line conversions
llvm-svn: 300569
This commit is contained in:
parent
ea9c5465dc
commit
04e5ab3501
|
@ -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).
|
||||
|
|
|
@ -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 = {[] {}};
|
||||
|
|
Loading…
Reference in New Issue