[clang-tidy] Fixes to misc-forwarding-reference-overload check.
* Style fixes to tests * Make it work consistently on all platforms Patch by András Leitereg! llvm-svn: 300320
This commit is contained in:
parent
e6ef099dcd
commit
6f0e2ac858
|
@ -56,7 +56,7 @@ AST_MATCHER_P(TemplateTypeParmDecl, hasDefaultArgument,
|
||||||
return Node.hasDefaultArgument() &&
|
return Node.hasDefaultArgument() &&
|
||||||
TypeMatcher.matches(Node.getDefaultArgument(), Finder, Builder);
|
TypeMatcher.matches(Node.getDefaultArgument(), Finder, Builder);
|
||||||
}
|
}
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
|
void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
|
||||||
// Forwarding references require C++11 or later.
|
// Forwarding references require C++11 or later.
|
||||||
|
@ -123,7 +123,8 @@ void ForwardingReferenceOverloadCheck::check(
|
||||||
(OtherCtor->isCopyConstructor() ? EnabledCopy : EnabledMove) = true;
|
(OtherCtor->isCopyConstructor() ? EnabledCopy : EnabledMove) = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Copy = !DisabledCopy || EnabledCopy, Move = !DisabledMove || EnabledMove;
|
bool Copy = !EnabledMove && !DisabledMove && !DisabledCopy || EnabledCopy;
|
||||||
|
bool Move = !DisabledMove || EnabledMove;
|
||||||
if (!Copy && !Move)
|
if (!Copy && !Move)
|
||||||
return;
|
return;
|
||||||
diag(Ctor->getLocation(),
|
diag(Ctor->getLocation(),
|
||||||
|
|
|
@ -1,44 +1,37 @@
|
||||||
// RUN: %check_clang_tidy %s misc-forwarding-reference-overload %t -- -- -std=c++14
|
// RUN: %check_clang_tidy %s misc-forwarding-reference-overload %t -- -- -std=c++14
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
template <bool B, class T = void>
|
template <bool B, class T = void> struct enable_if { typedef T type; };
|
||||||
struct enable_if { typedef T type; };
|
|
||||||
|
|
||||||
template <class T>
|
template <class T> struct enable_if<true, T> { typedef T type; };
|
||||||
struct enable_if<true, T> { typedef T type; };
|
|
||||||
|
|
||||||
template <bool B, class T = void>
|
template <bool B, class T = void>
|
||||||
using enable_if_t = typename enable_if<B, T>::type;
|
using enable_if_t = typename enable_if<B, T>::type;
|
||||||
|
|
||||||
template <class T>
|
template <class T> struct enable_if_nice { typedef T type; };
|
||||||
struct enable_if_nice { typedef T type; };
|
} // namespace std
|
||||||
}
|
|
||||||
|
|
||||||
namespace foo {
|
namespace foo {
|
||||||
template <class T>
|
template <class T> struct enable_if { typedef T type; };
|
||||||
struct enable_if { typedef T type; };
|
} // namespace foo
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> constexpr bool just_true = true;
|
||||||
constexpr bool just_true = true;
|
|
||||||
|
|
||||||
class Test1 {
|
class Test1 {
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T> Test1(T &&n);
|
||||||
Test1(T &&n);
|
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> Test1(T &&n, int i = 5, ...);
|
||||||
Test1(T &&n, int i = 5, ...);
|
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]
|
|
||||||
|
|
||||||
template <typename T, typename U = typename std::enable_if_nice<T>::type>
|
template <typename T, typename U = typename std::enable_if_nice<T>::type>
|
||||||
Test1(T &&n);
|
Test1(T &&n);
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Test1(T &&n, typename foo::enable_if<long>::type i = 5, ...);
|
Test1(T &&n, typename foo::enable_if<long>::type i = 5, ...);
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors
|
||||||
|
|
||||||
Test1(const Test1 &other) {}
|
Test1(const Test1 &other) {}
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
|
||||||
|
@ -50,19 +43,19 @@ public:
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename U>
|
template <typename U> class Test2 {
|
||||||
class Test2 {
|
|
||||||
public:
|
public:
|
||||||
// Two parameters without default value, can't act as copy / move constructor.
|
// Two parameters without default value, can't act as copy / move constructor.
|
||||||
template <typename T, class V>
|
template <typename T, class V> Test2(T &&n, V &&m, int i = 5, ...);
|
||||||
Test2(T &&n, V &&m, int i = 5, ...);
|
|
||||||
|
|
||||||
// Guarded with enable_if.
|
// Guarded with enable_if.
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Test2(T &&n, int i = 5, std::enable_if_t<sizeof(int) < sizeof(long), int> a = 5, ...);
|
Test2(T &&n, int i = 5,
|
||||||
|
std::enable_if_t<sizeof(int) < sizeof(long), int> a = 5, ...);
|
||||||
|
|
||||||
// Guarded with enable_if.
|
// Guarded with enable_if.
|
||||||
template <typename T, typename X = typename std::enable_if<sizeof(int) < sizeof(long), double>::type &>
|
template <typename T, typename X = typename std::enable_if<
|
||||||
|
sizeof(int) < sizeof(long), double>::type &>
|
||||||
Test2(T &&n);
|
Test2(T &&n);
|
||||||
|
|
||||||
// Guarded with enable_if.
|
// Guarded with enable_if.
|
||||||
|
@ -74,29 +67,24 @@ public:
|
||||||
Test2(T &&n, double d = 0.0);
|
Test2(T &&n, double d = 0.0);
|
||||||
|
|
||||||
// Not a forwarding reference parameter.
|
// Not a forwarding reference parameter.
|
||||||
template <typename T>
|
template <typename T> Test2(const T &&n);
|
||||||
Test2(const T &&n);
|
|
||||||
|
|
||||||
// Not a forwarding reference parameter.
|
// Not a forwarding reference parameter.
|
||||||
Test2(int &&x);
|
Test2(int &&x);
|
||||||
|
|
||||||
// Two parameters without default value, can't act as copy / move constructor.
|
// Two parameters without default value, can't act as copy / move constructor.
|
||||||
template <typename T>
|
template <typename T> Test2(T &&n, int x);
|
||||||
Test2(T &&n, int x);
|
|
||||||
|
|
||||||
// Not a forwarding reference parameter.
|
// Not a forwarding reference parameter.
|
||||||
template <typename T>
|
template <typename T> Test2(U &&n);
|
||||||
Test2(U &&n);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// The copy and move constructors are both disabled.
|
// The copy and move constructors are both disabled.
|
||||||
class Test3 {
|
class Test3 {
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T> Test3(T &&n);
|
||||||
Test3(T &&n);
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T> Test3(T &&n, int I = 5, ...);
|
||||||
Test3(T &&n, int I = 5, ...);
|
|
||||||
|
|
||||||
Test3(const Test3 &rhs) = delete;
|
Test3(const Test3 &rhs) = delete;
|
||||||
|
|
||||||
|
@ -107,31 +95,26 @@ private:
|
||||||
// Both the copy and the (compiler generated) move constructors can be hidden.
|
// Both the copy and the (compiler generated) move constructors can be hidden.
|
||||||
class Test4 {
|
class Test4 {
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T> Test4(T &&n);
|
||||||
Test4(T &&n);
|
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors [misc-forwarding-reference-overload]
|
|
||||||
|
|
||||||
Test4(const Test4 &rhs);
|
Test4(const Test4 &rhs);
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
|
||||||
};
|
};
|
||||||
|
|
||||||
// Only the (compiler generated) copy constructor can be hidden.
|
// Nothing can be hidden, the copy constructor is implicitly deleted.
|
||||||
// FIXME: Temporarily disabled due to failer on windows build bots.
|
class Test5 {
|
||||||
//class Test5 {
|
public:
|
||||||
//public:
|
template <typename T> Test5(T &&n);
|
||||||
// template <typename T>
|
|
||||||
// Test5(T &&n);
|
Test5(Test5 &&rhs) = delete;
|
||||||
// // CM: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy constructor [misc-forwarding-reference-overload]
|
};
|
||||||
//
|
|
||||||
// Test5(Test5 &&rhs) = delete;
|
|
||||||
//};
|
|
||||||
|
|
||||||
// Only the move constructor can be hidden.
|
// Only the move constructor can be hidden.
|
||||||
class Test6 {
|
class Test6 {
|
||||||
public:
|
public:
|
||||||
template <typename T>
|
template <typename T> Test6(T &&n);
|
||||||
Test6(T &&n);
|
// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the move constructor
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the move constructor [misc-forwarding-reference-overload]
|
|
||||||
|
|
||||||
Test6(Test6 &&rhs);
|
Test6(Test6 &&rhs);
|
||||||
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
|
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
|
||||||
|
|
Loading…
Reference in New Issue