C++11 inheriting constructors: support for inheriting constructor templates.

llvm-svn: 179151
diff --git a/clang/test/CXX/special/class.inhctor/elsewhere.cpp b/clang/test/CXX/special/class.inhctor/elsewhere.cpp
index 184e902..b986f65 100644
--- a/clang/test/CXX/special/class.inhctor/elsewhere.cpp
+++ b/clang/test/CXX/special/class.inhctor/elsewhere.cpp
@@ -55,3 +55,10 @@
   using A<T>::A; // expected-error {{'A<bool>' is not a direct base of 'F<bool>'}}
 };
 F<bool> fb; // expected-note {{here}}
+
+template<typename T>
+struct G : T {
+  using T::T;
+  G(int &) : G(0) {}
+};
+G<B1> g(123);
diff --git a/clang/test/CXX/special/class.inhctor/p1.cpp b/clang/test/CXX/special/class.inhctor/p1.cpp
index 57e9150..7300495 100644
--- a/clang/test/CXX/special/class.inhctor/p1.cpp
+++ b/clang/test/CXX/special/class.inhctor/p1.cpp
@@ -2,17 +2,24 @@
 // Per a core issue (no number yet), an ellipsis is always dropped.
 struct A {
   A(...); // expected-note {{here}}
-  A(int = 0, int = 0, int = 0, int = 0, ...); // expected-note 5{{here}}
+  A(int = 0, int = 0, int = 0, int = 0, ...); // expected-note 9{{here}}
   A(int = 0, int = 0, ...); // expected-note {{here}}
+
+  template<typename T> A(T, int = 0, ...); // expected-note 5{{here}}
+
+  template<typename T, int N> A(const T (&)[N]); // expected-note 2{{here}}
+  template<typename T, int N> A(const T (&)[N], int = 0); // expected-note 2{{here}}
 };
 
-struct B : A { // expected-note 3{{candidate}}
-  using A::A; // expected-warning 3{{inheriting constructor does not inherit ellipsis}} expected-note 4{{candidate}} expected-note 2{{deleted}}
+struct B : A { // expected-note 6{{candidate}}
+  using A::A; // expected-warning 4{{inheriting constructor does not inherit ellipsis}} expected-note 16{{candidate}} expected-note 3{{deleted}}
 };
 
+struct C {} c;
+
 B b0{};
 // expected-error@-1 {{call to implicitly-deleted default constructor}}
-// expected-note@9 {{default constructor of 'B' is implicitly deleted because base class 'A' has multiple default constructors}}
+// expected-note@-8 {{default constructor of 'B' is implicitly deleted because base class 'A' has multiple default constructors}}
 
 B b1{1};
 // FIXME: explain why the inheriting constructor was deleted
@@ -29,3 +36,16 @@
 
 B b5{1,2,3,4,5};
 // expected-error@-1 {{no matching constructor for initialization of 'B'}}
+
+B b6{c};
+// ok
+
+B b7{c,0};
+// ok
+
+B b8{c,0,1};
+// expected-error@-1 {{no matching constructor}}
+
+B b9{"foo"};
+// FIXME: explain why the inheriting constructor was deleted
+// expected-error@-2 {{call to deleted constructor of 'B'}}
diff --git a/clang/test/CXX/special/class.inhctor/p2.cpp b/clang/test/CXX/special/class.inhctor/p2.cpp
index e426738..e6abd68 100644
--- a/clang/test/CXX/special/class.inhctor/p2.cpp
+++ b/clang/test/CXX/special/class.inhctor/p2.cpp
@@ -3,7 +3,7 @@
 template<int> struct X {};
 
 // Constructor characteristics are:
-//   - the template parameter list [FIXME]
+//   - the template parameter list
 //   - the parameter-type-list
 //   - absence or presence of explicit
 //   - absence or presence of constexpr
@@ -85,3 +85,37 @@
 constexpr ConstexprEval3 ce{4, "foobar"};
 static_assert(ce.k == 'a', "");
 static_assert(ce.k2 == 'x', "");
+
+
+struct TemplateCtors {
+  constexpr TemplateCtors() {}
+  template<template<int> class T> TemplateCtors(X<0>, T<0>);
+  template<int N> TemplateCtors(X<1>, X<N>);
+  template<typename T> TemplateCtors(X<2>, T);
+
+  template<typename T = int> TemplateCtors(int, int = 0, int = 0); // expected-note {{inherited from here}}
+};
+
+struct UsingTemplateCtors : TemplateCtors {
+  using TemplateCtors::TemplateCtors; // expected-note 4{{here}} expected-note {{candidate}}
+
+  constexpr UsingTemplateCtors(X<0>, X<0>) {}
+  constexpr UsingTemplateCtors(X<1>, X<1>) {}
+  constexpr UsingTemplateCtors(X<2>, X<2>) {}
+
+  template<int = 0> constexpr UsingTemplateCtors(int) {} // expected-note {{candidate}}
+  template<typename T = void> constexpr UsingTemplateCtors(int, int) {}
+  template<typename T, typename U> constexpr UsingTemplateCtors(int, int, int) {}
+};
+
+template<int> struct Y {};
+constexpr UsingTemplateCtors uct1{ X<0>{}, X<0>{} };
+constexpr UsingTemplateCtors uct2{ X<0>{}, Y<0>{} }; // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr}}
+constexpr UsingTemplateCtors uct3{ X<1>{}, X<0>{} }; // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr}}
+constexpr UsingTemplateCtors uct4{ X<1>{}, X<1>{} };
+constexpr UsingTemplateCtors uct5{ X<2>{}, 0 }; // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr}}
+constexpr UsingTemplateCtors uct6{ X<2>{}, X<2>{} };
+
+constexpr UsingTemplateCtors utc7{ 0 }; // expected-error {{ambiguous}}
+constexpr UsingTemplateCtors utc8{ 0, 0 }; // ok
+constexpr UsingTemplateCtors utc9{ 0, 0, 0 }; // expected-error {{must be initialized by a constant expression}} expected-note {{non-constexpr}}
diff --git a/clang/test/CXX/special/class.inhctor/p3.cpp b/clang/test/CXX/special/class.inhctor/p3.cpp
index f71ab16..7aaaa7a 100644
--- a/clang/test/CXX/special/class.inhctor/p3.cpp
+++ b/clang/test/CXX/special/class.inhctor/p3.cpp
@@ -46,3 +46,13 @@
   friend T3<int>::T3(int);
   friend T3<int>::T3(int, int);
 };
+
+struct B4 {
+  template<typename T> explicit B4(T, int = 0);
+};
+template<typename T> struct T4 : B4 {
+  using B4::B4; // expected-note {{here}}
+  template<typename U> T4(U);
+};
+T4<void> t4a = {0};
+T4<void> t4b = {0, 0}; // expected-error {{chosen constructor is explicit}}
diff --git a/clang/test/CXX/special/class.inhctor/p4.cpp b/clang/test/CXX/special/class.inhctor/p4.cpp
index eea3bf2..512705e 100644
--- a/clang/test/CXX/special/class.inhctor/p4.cpp
+++ b/clang/test/CXX/special/class.inhctor/p4.cpp
@@ -44,11 +44,13 @@
 // It is deleted if the corresponding constructor [...] is deleted.
 struct G {
   G(int) = delete;
+  template<typename T> G(T*) = delete;
 };
 struct H : G {
-  using G::G; // expected-note {{marked deleted here}}
+  using G::G; // expected-note 2{{marked deleted here}}
 };
-H h(5); // expected-error {{call to implicitly-deleted function of 'H'}}
+H h1(5); // expected-error {{call to implicitly-deleted function 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
diff --git a/clang/test/CXX/special/class.inhctor/p7.cpp b/clang/test/CXX/special/class.inhctor/p7.cpp
index 9ae160f..a57e855 100644
--- a/clang/test/CXX/special/class.inhctor/p7.cpp
+++ b/clang/test/CXX/special/class.inhctor/p7.cpp
@@ -27,3 +27,21 @@
 };
 B4<char> b4c;
 B4<int> b4i; // expected-note {{here}}
+
+struct B5 {
+  template<typename T> B5(T); // expected-note {{previous constructor}}
+};
+struct B6 {
+  template<typename T> B6(T); // expected-note {{conflicting constructor}}
+};
+struct B7 {
+  template<typename T, int> B7(T);
+};
+struct D56 : B5, B6, B7 {
+  using B5::B5; // expected-note {{inherited here}}
+  using B6::B6; // expected-error {{already inherited}}
+};
+struct D57 : B5, B6, B7 {
+  using B5::B5;
+  using B7::B7; // ok, not the same signature
+};
diff --git a/clang/test/CXX/special/class.inhctor/p8.cpp b/clang/test/CXX/special/class.inhctor/p8.cpp
index e2b07df..0c85738 100644
--- a/clang/test/CXX/special/class.inhctor/p8.cpp
+++ b/clang/test/CXX/special/class.inhctor/p8.cpp
@@ -19,3 +19,12 @@
 constexpr B b1{k};
 
 static_assert(a0.rval && !a1.rval && b0.rval && !b1.rval, "");
+
+struct C {
+  template<typename T> constexpr C(T t) : v(t) {}
+  int v;
+};
+struct D : C {
+  using C::C;
+};
+static_assert(D(123).v == 123, "");