1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx98-14 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
4 struct X0
{ // expected-note {{candidate constructor (the implicit copy constructor) not viable}}
5 #if __cplusplus >= 201103L // C++11 or later
6 // expected-note@-2 {{candidate constructor (the implicit move constructor) not viable}}
8 X0(int); // expected-note{{candidate}}
9 template<typename T
> X0(T
); // expected-note {{candidate}}
10 template<typename T
, typename U
> X0(T
*, U
*); // expected-note {{candidate}}
13 template<typename T
> X0() : f0(T::foo
) {} // expected-note {{candidate}}
19 void test_X0(int i
, float f
) {
31 X0
x0g(f
, &i
); // expected-error{{no matching constructor}}
37 template<typename U
> X1(const X1
<U
>&);
46 explicit Outer(const A
& a
) : alloc(a
) { }
49 void test_X1(X1
<int> xi
) {
55 template<class C
> struct A
{};
56 template <> struct A
<int>{A(const A
<int>&);};
57 struct B
{ A
<int> x
; B(B
& a
) : x(a
.x
) {} };
60 X2(); // precxx17-note{{candidate constructor}}
61 X2(X2
&); // precxx17-note {{candidate constructor}}
62 template<typename T
> X2(T
); // precxx17-note {{candidate template ignored: instantiation would take its own class type by value}}
65 X2
test(bool Cond
, X2 x2
) {
67 return x2
; // okay, uses copy constructor
69 return X2(); // precxx17-error{{no matching constructor}}
73 template<typename T
> X3(T
);
76 template<> X3::X3(X3
); // expected-error{{must pass its first argument by reference}}
82 template<typename T
> X4(const T
&, int = 17);
85 X4
test_X4(bool Cond
, X4 x4
) {
86 X4
a(x4
, 17); // okay, constructor template
87 X4
b(x4
); // okay, copy constructor
91 // Instantiation of a non-dependent use of a constructor
92 struct DefaultCtorHasDefaultArg
{
93 explicit DefaultCtorHasDefaultArg(int i
= 17);
97 void default_ctor_inst() {
98 DefaultCtorHasDefaultArg def
;
101 template void default_ctor_inst
<int>();
110 template<typename T
> X6(T
);
121 template<class T
> foo(T
&);
135 // Don't blow out the stack trying to call an illegal constructor
136 // instantiation. We intentionally allow implicit instantiations to
137 // exist, so make sure they're unusable.
138 namespace self_by_value
{
139 template <class T
, class U
> struct A
{
141 A(const A
<T
,U
> &o
) {}
145 void helper(A
<int,float>);
147 void test1(A
<int,int> a
) {
151 helper(A
<int,int>());
155 namespace self_by_value_2
{
156 template <class T
, class U
> struct A
{
157 A() {} // precxx17-note {{not viable: requires 0 arguments}}
158 A(A
<T
,U
> &o
) {} // precxx17-note {{not viable: expects an lvalue}}
159 A(A
<T
,T
> o
) {} // precxx17-note {{ignored: instantiation takes its own class type by value}}
162 void helper_A(A
<int,int>); // precxx17-note {{passing argument to parameter here}}
164 helper_A(A
<int,int>()); // precxx17-error {{no matching constructor}}
168 namespace self_by_value_3
{
169 template <class T
, class U
> struct A
{
175 void helper_A(A
<int,int>);
176 void test_A(A
<int,int> b
) {