brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 703bec0 Raw
75 lines · cpp
1// RUN: %clang_cc1 -std=c++11 -verify %s2//3// Note: [class.inhctor] was removed by P0136R1. This tests the new behavior4// for the wording that used to be there.5 6template<int> struct X {};7 8// A[n inheriting] constructor [...] has the same access as the corresponding9// constructor [in the base class].10struct A {11public:12  A(X<0>) {}13protected:14  A(X<1>) {} // expected-note 2{{declared protected here}}15private:16  A(X<2>) {} // expected-note 2{{declared private here}}17  friend class FA;18};19 20struct B : A {21  using A::A;22  friend class FB;23};24 25B b0{X<0>{}};26B b1{X<1>{}}; // expected-error {{calling a protected constructor}}27B b2{X<2>{}}; // expected-error {{calling a private constructor}}28 29struct C : B {30  C(X<0> x) : B(x) {}31  C(X<1> x) : B(x) {}32};33 34struct FB {35  B b0{X<0>{}};36  B b1{X<1>{}};37};38 39struct FA : A {40  using A::A;41};42FA fa0{X<0>{}};43FA fa1{X<1>{}}; // expected-error {{calling a protected constructor}}44FA fa2{X<2>{}}; // expected-error {{calling a private constructor}}45 46 47// It is deleted if the corresponding constructor [...] is deleted.48struct G {49  G(int) = delete; // expected-note {{'G' has been explicitly marked deleted here}}50  template<typename T> G(T*) = delete; // expected-note {{'G<const char>' has been explicitly marked deleted here}}51};52struct H : G {53  using G::G;54};55H h1(5); // expected-error {{call to deleted constructor of 'H'}}56H h2("foo"); // expected-error {{call to deleted constructor of 'H'}}57 58 59// Core defect: It is also deleted if multiple base constructors generate the60// same signature.61namespace DRnnnn {62  struct A {63    constexpr A(int, float = 0) {}64    explicit A(int, int = 0) {} // expected-note {{candidate}}65 66    A(int, int, int = 0) = delete; // expected-note {{deleted}}67  };68  struct B : A {69    using A::A; // expected-note 2{{inherited here}}70  };71 72  constexpr B b0(0, 0.0f); // ok, constexpr73  B b1(0, 1); // expected-error {{call to constructor of 'B' is ambiguous}}74}75