// RUN: %check_clang_tidy %s bugprone-forwarding-reference-overload %t namespace std { template struct enable_if { typedef T type; }; template struct enable_if { typedef T type; }; template using enable_if_t = typename enable_if::type; template struct enable_if_nice { typedef T type; }; } // namespace std namespace foo { template struct enable_if { typedef T type; }; } // namespace foo template constexpr bool just_true = true; class Test1 { public: template Test1(T &&n); // CHECK-NOTES: [[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors [bugprone-forwarding-reference-overload] // CHECK-NOTES: 48:3: note: copy constructor declared here // CHECK-NOTES: 49:3: note: copy constructor declared here // CHECK-NOTES: 50:3: note: move constructor declared here template Test1(T &&n, int i = 5, ...); // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors // CHECK-NOTES: 48:3: note: copy constructor declared here // CHECK-NOTES: 49:3: note: copy constructor declared here // CHECK-NOTES: 50:3: note: move constructor declared here template ::type> Test1(T &&n); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors // CHECK-NOTES: 48:3: note: copy constructor declared here // CHECK-NOTES: 49:3: note: copy constructor declared here // CHECK-NOTES: 50:3: note: move constructor declared here template Test1(T &&n, typename foo::enable_if::type i = 5, ...); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors // CHECK-NOTES: 48:3: note: copy constructor declared here // CHECK-NOTES: 49:3: note: copy constructor declared here // CHECK-NOTES: 50:3: note: move constructor declared here Test1(const Test1 &other) {} Test1(Test1 &other) {} Test1(Test1 &&other) {} }; template class Test2 { public: // Two parameters without default value, can't act as copy / move constructor. template Test2(T &&n, V &&m, int i = 5, ...); // Guarded with enable_if. template Test2(T &&n, int i = 5, std::enable_if_t a = 5, ...); // Guarded with enable_if. template ::type &> Test2(T &&n); // Guarded with enable_if. template Test2(T &&n, typename std::enable_if>::type **a = nullptr); // Guarded with enable_if. template > *&&> Test2(T &&n, double d = 0.0); // Not a forwarding reference parameter. template 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 Test2(T &&n, int x); // Not a forwarding reference parameter. template Test2(U &&n); }; // The copy and move constructors are both disabled. class Test3 { public: template Test3(T &&n); template 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 Test4(T &&n); // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the copy and move constructors Test4(const Test4 &rhs); // CHECK-NOTES: :[[@LINE-1]]:3: note: copy constructor declared here }; // Nothing can be hidden, the copy constructor is implicitly deleted. class Test5 { public: template Test5(T &&n); Test5(Test5 &&rhs) = delete; }; // Only the move constructor can be hidden. class Test6 { public: template Test6(T &&n); // CHECK-NOTES: :[[@LINE-1]]:25: warning: constructor accepting a forwarding reference can hide the move constructor Test6(Test6 &&rhs); // CHECK-NOTES: :[[@LINE-1]]:3: note: move constructor declared here private: Test6(const Test6 &rhs); }; // Do not dereference a null BaseType. template class result_of; template class result_of<_Fp(_Args...)> { }; template using result_of_t = typename result_of<_Tp>::type; template struct __overload; template struct __overload<_Tp, _Types...> : __overload<_Types...> { using __overload<_Types...>::operator(); }; template using __best_match_t = typename result_of_t<__overload<_Types...>(_Tp&&)>::type; template class variant { public: template > constexpr variant(_Arg&& __arg) {} // CHECK-NOTES: :[[@LINE-1]]:13: warning: constructor accepting a forwarding reference can hide the copy and move constructors }; namespace std { template struct is_same { static constexpr bool value = false; }; template struct is_same { static constexpr bool value = true; }; template constexpr bool is_same_v = is_same::value; template struct remove_reference { using type = T; }; template struct remove_reference { using type = T; }; template struct remove_reference { using type = T; }; template using remove_reference_t = typename remove_reference::type; template struct remove_cv { using type = T; }; template struct remove_cv { using type = T; }; template struct remove_cv { using type = T; }; template struct remove_cv { using type = T; }; template using remove_cv_t = typename remove_cv::type; template struct remove_cvref { using type = remove_cv_t>; }; template using remove_cvref_t = typename remove_cvref::type; } // namespace std // Handle enable_if when used as a non-type template parameter. class Test7 { public: // Guarded with enable_if. template , int>, int>::type = 0> Test7(T &&t); // Guarded with enable_if. template , Test7> && !std::is_same_v, bool>, int> = true> Test7(T &&t); Test7(const Test7 &other) = default; Test7(Test7 &&other) = default; }; // Handle enable_if when used as a non-type template parameter following // a variadic template parameter pack. class Test8 { public: // Guarded with enable_if. template , Test8> || (sizeof...(A) > 0)>* = nullptr> Test8(T &&t, A &&... a); Test8(const Test8 &other) = default; Test8(Test8 &&other) = default; }; // Non-type template parameter failure cases. class Test9 { public: // Requires a default argument (such as a literal, implicit cast expression, etc.) template , bool>, int>> Test9(T &&t); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors // CHECK-NOTES: 240:3: note: copy constructor declared here // CHECK-NOTES: 241:3: note: move constructor declared here // Requires a default argument (such as a literal, implicit cast expression, etc.) template , long>>*> Test9(T &&t); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors // CHECK-NOTES: 240:3: note: copy constructor declared here // CHECK-NOTES: 241:3: note: move constructor declared here // Only std::enable_if or std::enable_if_t are supported template ::type* = nullptr> Test9(T &&t); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors // CHECK-NOTES: 240:3: note: copy constructor declared here // CHECK-NOTES: 241:3: note: move constructor declared here // Only std::enable_if or std::enable_if_t are supported template ::type = 0> Test9(T &&t); // CHECK-NOTES: :[[@LINE-1]]:3: warning: constructor accepting a forwarding reference can hide the copy and move constructors // CHECK-NOTES: 240:3: note: copy constructor declared here // CHECK-NOTES: 241:3: note: move constructor declared here Test9(const Test9 &other) = default; Test9(Test9 &&other) = default; }; template class Test10 { public: enum E {}; E e; Test10(T &&Item, E e) : e(e){} };