p4.cpp revision 651f13cea278ec967336033dd032faef0e9fc2ec
13b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher// RUN: %clang_cc1 -std=c++11 -verify %s 23b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher 33b20b9ee0da7f840369088874e3f806d71309d77Eric Christophertemplate<int> struct X {}; 43b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher 53b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher// A[n inheriting] constructor [...] has the same access as the corresponding 63b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher// constructor [in the base class]. 73b20b9ee0da7f840369088874e3f806d71309d77Eric Christopherstruct A { 83b20b9ee0da7f840369088874e3f806d71309d77Eric Christopherpublic: 93b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher A(X<0>) {} 103b20b9ee0da7f840369088874e3f806d71309d77Eric Christopherprotected: 113b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher A(X<1>) {} 123b20b9ee0da7f840369088874e3f806d71309d77Eric Christopherprivate: 133b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher A(X<2>) {} // expected-note {{declared private here}} 143b20b9ee0da7f840369088874e3f806d71309d77Eric Christopher friend class FA; 15}; 16 17struct B : A { 18 using A::A; // expected-error {{private constructor}} expected-note {{implicitly declared protected here}} 19 friend class FB; 20}; 21 22B b0{X<0>{}}; 23B b1{X<1>{}}; // expected-error {{calling a protected constructor}} 24B b2{X<2>{}}; // expected-note {{first required here}} 25 26struct C : B { 27 C(X<0> x) : B(x) {} 28 C(X<1> x) : B(x) {} 29}; 30 31struct FB { 32 B b0{X<0>{}}; 33 B b1{X<1>{}}; 34}; 35 36struct FA : A { 37 using A::A; // expected-note 2{{here}} 38}; 39FA fa0{X<0>{}}; 40FA fa1{X<1>{}}; // expected-error {{calling a protected constructor}} 41FA fa2{X<2>{}}; // expected-error {{calling a private constructor}} 42 43 44// It is deleted if the corresponding constructor [...] is deleted. 45struct G { 46 G(int) = delete; // expected-note {{'G' has been explicitly marked deleted here}} 47 template<typename T> G(T*) = delete; // expected-note {{'G<const char>' has been explicitly marked deleted here}} 48}; 49struct H : G { 50 using G::G; // expected-note 2{{deleted constructor was inherited here}} 51}; 52H h1(5); // expected-error {{call to deleted constructor of 'H'}} 53H h2("foo"); // expected-error {{call to deleted constructor of 'H'}} 54 55 56// Core defect: It is also deleted if multiple base constructors generate the 57// same signature. 58namespace DRnnnn { 59 struct A { 60 constexpr A(int, float = 0) {} 61 explicit A(int, int = 0) {} // expected-note {{constructor cannot be inherited}} 62 63 A(int, int, int = 0) = delete; 64 }; 65 struct B : A { 66 using A::A; // expected-note {{here}} 67 }; 68 69 constexpr B b0(0, 0.0f); // ok, constexpr 70 B b1(0, 1); // expected-error {{call to deleted constructor of 'DRnnnn::B'}} 71} 72