Richard Smith | 4c163a0 | 2013-05-17 02:19:35 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 %s -verify |
| 2 | |
Richard Smith | 4c163a0 | 2013-05-17 02:19:35 +0000 | [diff] [blame] | 3 | namespace PR15757 { |
| 4 | struct S { |
| 5 | }; |
| 6 | |
| 7 | template<typename X, typename Y> struct T { |
| 8 | template<typename A> T(X x, A &&a) {} |
| 9 | |
| 10 | template<typename A> explicit T(A &&a) |
| 11 | noexcept(noexcept(T(X(), static_cast<A &&>(a)))) |
| 12 | : T(X(), static_cast<A &&>(a)) {} |
| 13 | }; |
| 14 | |
| 15 | template<typename X, typename Y> struct U : T<X, Y> { |
| 16 | using T<X, Y>::T; |
| 17 | }; |
| 18 | |
| 19 | U<S, char> foo(char ch) { return U<S, char>(ch); } |
| 20 | |
| 21 | int main() { |
| 22 | U<S, int> a(42); |
| 23 | U<S, char> b('4'); |
| 24 | return 0; |
| 25 | } |
| 26 | } |
Richard Smith | 09d5b3a | 2014-05-01 00:35:04 +0000 | [diff] [blame] | 27 | |
| 28 | namespace WrongIdent { |
| 29 | struct A {}; |
| 30 | struct B : A {}; |
| 31 | struct C : B { |
| 32 | using B::A; |
| 33 | }; |
| 34 | } |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 35 | |
| 36 | namespace DefaultCtorConflict { |
| 37 | struct A { A(int = 0); }; |
| 38 | struct B : A { |
| 39 | using A::A; |
| 40 | } b; // ok, not ambiguous, inherited constructor suppresses implicit default constructor |
| 41 | struct C { |
| 42 | B b; |
| 43 | } c; |
| 44 | } |
Richard Smith | 80a4702 | 2016-06-29 01:10:27 +0000 | [diff] [blame] | 45 | |
| 46 | namespace InvalidConstruction { |
| 47 | struct A { A(int); }; |
| 48 | struct B { B() = delete; }; |
| 49 | struct C : A, B { using A::A; }; |
| 50 | // Initialization here is performed as if by a defaulted default constructor, |
| 51 | // which would be ill-formed (in the immediate context) in this case because |
| 52 | // it would be defined as deleted. |
| 53 | template<typename T> void f(decltype(T(0))*); |
| 54 | template<typename T> int &f(...); |
| 55 | int &r = f<C>(0); |
| 56 | } |
Richard Smith | 7c2bcc9 | 2016-09-07 02:14:33 +0000 | [diff] [blame] | 57 | |
| 58 | namespace ExplicitConv { |
Richard Smith | 836a3b4 | 2017-01-13 20:46:54 +0000 | [diff] [blame] | 59 | struct B {}; |
Richard Smith | 7c2bcc9 | 2016-09-07 02:14:33 +0000 | [diff] [blame] | 60 | struct D : B { // expected-note 3{{candidate}} |
Richard Smith | 836a3b4 | 2017-01-13 20:46:54 +0000 | [diff] [blame] | 61 | using B::B; |
Richard Smith | 7c2bcc9 | 2016-09-07 02:14:33 +0000 | [diff] [blame] | 62 | }; |
| 63 | struct X { explicit operator B(); } x; |
| 64 | struct Y { explicit operator D(); } y; |
| 65 | |
| 66 | D dx(x); // expected-error {{no matching constructor}} |
| 67 | D dy(y); |
| 68 | } |
| 69 | |
| 70 | namespace NestedListInit { |
Richard Smith | 836a3b4 | 2017-01-13 20:46:54 +0000 | [diff] [blame] | 71 | struct B { B(); } b; // expected-note 3{{candidate}} |
| 72 | struct D : B { // expected-note 14{{not viable}} |
| 73 | using B::B; |
Richard Smith | 7c2bcc9 | 2016-09-07 02:14:33 +0000 | [diff] [blame] | 74 | }; |
| 75 | // This is a bit weird. We're allowed one pair of braces for overload |
| 76 | // resolution, and one more pair of braces due to [over.ics.list]/2. |
| 77 | B b1 = {b}; |
| 78 | B b2 = {{b}}; |
| 79 | B b3 = {{{b}}}; // expected-error {{no match}} |
Richard Smith | 836a3b4 | 2017-01-13 20:46:54 +0000 | [diff] [blame] | 80 | // Per a proposed defect resolution, we don't get to call |
| 81 | // D's version of B::B(const B&) here. |
| 82 | D d0 = b; // expected-error {{no viable conversion}} |
| 83 | D d1 = {b}; // expected-error {{no match}} |
| 84 | D d2 = {{b}}; // expected-error {{no match}} |
| 85 | D d3 = {{{b}}}; // expected-error {{no match}} |
Richard Smith | 7c2bcc9 | 2016-09-07 02:14:33 +0000 | [diff] [blame] | 86 | D d4 = {{{{b}}}}; // expected-error {{no match}} |
| 87 | } |
Richard Smith | 836a3b4 | 2017-01-13 20:46:54 +0000 | [diff] [blame] | 88 | |
| 89 | namespace PR31606 { |
| 90 | // PR31606: as part of a proposed defect resolution, do not consider |
| 91 | // inherited constructors that would be copy constructors for any class |
| 92 | // between the declaring class and the constructed class (inclusive). |
| 93 | struct Base {}; |
| 94 | |
| 95 | struct A : Base { |
| 96 | using Base::Base; |
| 97 | bool operator==(A const &) const; // expected-note {{no known conversion from 'PR31606::B' to 'const PR31606::A' for 1st argument}} |
| 98 | }; |
| 99 | |
| 100 | struct B : Base { |
| 101 | using Base::Base; |
| 102 | }; |
| 103 | |
| 104 | bool a = A{} == A{}; |
| 105 | // Note, we do *not* allow operator=='s argument to use the inherited A::A(Base&&) constructor to construct from B{}. |
| 106 | bool b = A{} == B{}; // expected-error {{invalid operands}} |
| 107 | } |
Richard Smith | 171e4b5 | 2017-02-15 04:18:23 +0000 | [diff] [blame] | 108 | |
| 109 | namespace implicit_member_srcloc { |
| 110 | template<class T> |
| 111 | struct S3 { |
| 112 | }; |
| 113 | |
| 114 | template<class T> |
| 115 | struct S2 { |
| 116 | S2(S3<T> &&); |
| 117 | }; |
| 118 | |
| 119 | template<class T> |
| 120 | struct S1 : S2<T> { |
| 121 | using S2<T>::S2; |
| 122 | S1(); |
| 123 | }; |
| 124 | |
| 125 | template<class T> |
| 126 | struct S0 { |
| 127 | S0(); |
| 128 | S0(S0&&) = default; |
| 129 | S1<T> m1; |
| 130 | }; |
| 131 | |
| 132 | void foo1() { |
| 133 | S0<int> s0; |
| 134 | } |
| 135 | } |