1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
// RUN: %check_clang_tidy %s misc-forwarding-reference-overload %t -- -- -std=c++14
namespace std {
template <bool B, class T = void>
struct enable_if { typedef T type; };
template <class T>
struct enable_if<true, T> { typedef T type; };
template <bool B, class T = void>
using enable_if_t = typename enable_if<B, T>::type;
template <class T>
struct enable_if_nice { typedef T type; };
}
namespace foo {
template <class T>
struct enable_if { typedef T type; };
}
template <typename T>
constexpr bool just_true = true;
class Test1 {
public:
template <typename T>
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]
template <typename T>
Test1(T &&n, int i = 5, ...);
// 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>
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]
template <typename T>
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]
Test1(const Test1 &other) {}
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
Test1(Test1 &other) {}
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
Test1(Test1 &&other) {}
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
};
template <typename U>
class Test2 {
public:
// Two parameters without default value, can't act as copy / move constructor.
template <typename T, class V>
Test2(T &&n, V &&m, int i = 5, ...);
// Guarded with enable_if.
template <typename T>
Test2(T &&n, int i = 5, std::enable_if_t<sizeof(int) < sizeof(long), int> a = 5, ...);
// Guarded with enable_if.
template <typename T, typename X = typename std::enable_if<sizeof(int) < sizeof(long), double>::type &>
Test2(T &&n);
// Guarded with enable_if.
template <typename T>
Test2(T &&n, typename std::enable_if<just_true<T>>::type **a = nullptr);
// Guarded with enable_if.
template <typename T, typename X = std::enable_if_t<just_true<T>> *&&>
Test2(T &&n, double d = 0.0);
// Not a forwarding reference parameter.
template <typename T>
Test2(const T &&n);
// Not a forwarding reference parameter.
Test2(int &&x);
// Two parameters without default value, can't act as copy / move constructor.
template <typename T>
Test2(T &&n, int x);
// Not a forwarding reference parameter.
template <typename T>
Test2(U &&n);
};
// The copy and move constructors are both disabled.
class Test3 {
public:
template <typename T>
Test3(T &&n);
template <typename T>
Test3(T &&n, int I = 5, ...);
Test3(const Test3 &rhs) = delete;
private:
Test3(Test3 &&rhs);
};
// Both the copy and the (compiler generated) move constructors can be hidden.
class Test4 {
public:
template <typename T>
Test4(T &&n);
// 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);
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: copy constructor declared here
};
// Only the (compiler generated) copy constructor can be hidden.
// FIXME: Temporarily disabled due to failer on windows build bots.
//class Test5 {
//public:
// template <typename T>
// Test5(T &&n);
// // 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.
class Test6 {
public:
template <typename T>
Test6(T &&n);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the move constructor [misc-forwarding-reference-overload]
Test6(Test6 &&rhs);
// CHECK-MESSAGES: :[[@LINE-1]]:3: note: move constructor declared here
private:
Test6(const Test6 &rhs);
};
|