brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.2 KiB · 13f00be Raw
181 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify=expected,precxx17 %std_cxx98-14 %s2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s3 4struct X0 { // expected-note {{candidate constructor (the implicit copy constructor) not viable}}5#if __cplusplus >= 201103L // C++11 or later6// expected-note@-2 {{candidate constructor (the implicit move constructor) not viable}}7#endif8  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}}11  12  // PR476113  template<typename T> X0() : f0(T::foo) {} // expected-note {{candidate}}14  int f0;15};16 17void accept_X0(X0);18 19void test_X0(int i, float f) {20  X0 x0a(i);21  X0 x0b(f);22  X0 x0c = i;23  X0 x0d = f;24  accept_X0(i);25  accept_X0(&i);26  accept_X0(f);27  accept_X0(&f);28  X0 x0e(&i, &f);29  X0 x0f(&f, &i);30  31  X0 x0g(f, &i); // expected-error{{no matching constructor}}32}33 34template<typename T>35struct X1 {36  X1(const X1&);37  template<typename U> X1(const X1<U>&);38};39 40template<typename T>41struct Outer {42  typedef X1<T> A;43  44  A alloc;45  46  explicit Outer(const A& a) : alloc(a) { }47};48 49void test_X1(X1<int> xi) {50  Outer<int> oi(xi);51  Outer<float> of(xi);52}53 54// PR465555template<class C> struct A {};56template <> struct A<int>{A(const A<int>&);};57struct B { A<int> x; B(B& a) : x(a.x) {} };58 59struct X2 {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}}63};64 65X2 test(bool Cond, X2 x2) {66  if (Cond)67    return x2; // okay, uses copy constructor68  69  return X2(); // precxx17-error{{no matching constructor}}70}71 72struct X3 {73  template<typename T> X3(T);74};75 76template<> X3::X3(X3); // No error (template constructor)77 78struct X4 {79  X4();80  ~X4();81  X4(X4&);82  template<typename T> X4(const T&, int = 17);83};84 85X4 test_X4(bool Cond, X4 x4) {86  X4 a(x4, 17); // okay, constructor template87  X4 b(x4); // okay, copy constructor88  return X4();89}90 91// Instantiation of a non-dependent use of a constructor92struct DefaultCtorHasDefaultArg {93  explicit DefaultCtorHasDefaultArg(int i = 17);94};95 96template<typename T>97void default_ctor_inst() {98  DefaultCtorHasDefaultArg def;99}100 101template void default_ctor_inst<int>();102 103template<typename T>104struct X5 {105  X5();106  X5(const T &);107};108 109struct X6 {110  template<typename T> X6(T);111};112 113void test_X5_X6() {114  X5<X6> tf;115  X5<X6> tf2(tf);116}117 118namespace PR8182 {119  struct foo {120    foo();121    template<class T> foo(T&);122 123  private:124    foo(const foo&);125  };126 127  void test_foo() {128    foo f1;129    foo f2(f1);130    foo f3 = f1;131  }132 133}134 135// Don't blow out the stack trying to call an illegal constructor136// instantiation.  We intentionally allow implicit instantiations to137// exist, so make sure they're unusable.138namespace self_by_value {139  template <class T, class U> struct A {140    A() {}141    A(const A<T,U> &o) {}142    A(A<T,T> o) {} // expected-error{{copy constructor must pass its first argument by reference}}143  };144 145  void helper(A<int,float>);146 147  void test1(A<int,int> a) { // expected-note{{in instantiation of template class 'self_by_value::A<int, int>'}}148    helper(a);149  }150  void test2() {151    helper(A<int,int>());152  }153}154 155namespace 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) {} // expected-error{{copy constructor must pass its first argument by reference}}160  };161 162  void helper_A(A<int,int>); // precxx17-note {{passing argument to parameter here}}163  void test_A() {164    helper_A(A<int,int>()); // precxx17-error {{no matching constructor}} \165                            // expected-note{{in instantiation of template class 'self_by_value_2::A<int, int>'}}166  }167}168 169namespace self_by_value_3 {170  template <class T, class U> struct A {171    A() {}172    A(A<T,U> &o) {}173    A(A<T,T> o) {} // expected-error{{copy constructor must pass its first argument by reference}}174  };175 176  void helper_A(A<int,int>);177  void test_A(A<int,int> b) { // expected-note{{in instantiation of template class 'self_by_value_3::A<int, int>'}}178    helper_A(b);179  }180}181