reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    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
// RUN: %clang_cc1 -std=c++11 -verify %s
//
// Note: [class.inhctor] was removed by P0136R1. This tests the new behavior
// for the wording that used to be there.

template<int> struct X {};

// A[n inheriting] constructor [...] has the same access as the corresponding
// constructor [in the base class].
struct A {
public:
  A(X<0>) {}
protected:
  A(X<1>) {} // expected-note 2{{declared protected here}}
private:
  A(X<2>) {} // expected-note 2{{declared private here}}
  friend class FA;
};

struct B : A {
  using A::A;
  friend class FB;
};

B b0{X<0>{}};
B b1{X<1>{}}; // expected-error {{calling a protected constructor}}
B b2{X<2>{}}; // expected-error {{calling a private constructor}}

struct C : B {
  C(X<0> x) : B(x) {}
  C(X<1> x) : B(x) {}
};

struct FB {
  B b0{X<0>{}};
  B b1{X<1>{}};
};

struct FA : A {
  using A::A;
};
FA fa0{X<0>{}};
FA fa1{X<1>{}}; // expected-error {{calling a protected constructor}}
FA fa2{X<2>{}}; // expected-error {{calling a private constructor}}


// It is deleted if the corresponding constructor [...] is deleted.
struct G {
  G(int) = delete; // expected-note {{'G' has been explicitly marked deleted here}}
  template<typename T> G(T*) = delete; // expected-note {{'G<const char>' has been explicitly marked deleted here}}
};
struct H : G {
  using G::G;
};
H h1(5); // expected-error {{call to deleted constructor of 'H'}}
H h2("foo"); // expected-error {{call to deleted constructor of 'H'}}


// Core defect: It is also deleted if multiple base constructors generate the
// same signature.
namespace DRnnnn {
  struct A {
    constexpr A(int, float = 0) {}
    explicit A(int, int = 0) {} // expected-note {{candidate}}

    A(int, int, int = 0) = delete; // expected-note {{deleted}}
  };
  struct B : A {
    using A::A; // expected-note 2{{inherited here}}
  };

  constexpr B b0(0, 0.0f); // ok, constexpr
  B b1(0, 1); // expected-error {{call to constructor of 'DRnnnn::B' is ambiguous}}
}