copy-ctor-assign.cpp 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // RUN: %clang_cc1 -fsyntax-only -verify %s
  2. // Make sure that copy constructors and assignment operators are properly
  3. // generated when there is a matching
  4. // PR5072
  5. template<typename T>
  6. struct X {
  7. template<typename U>
  8. X(const X<U>& other)
  9. : value(other.value + 1) { } // expected-error{{binary expression}}
  10. template<typename U>
  11. X& operator=(const X<U>& other) {
  12. value = other.value + 1; // expected-error{{binary expression}}
  13. return *this;
  14. }
  15. T value;
  16. };
  17. struct Y {};
  18. X<int Y::*> test0(X<int Y::*> x) { return x; }
  19. X<int> test1(X<long> x) { return x; }
  20. X<int> test2(X<int Y::*> x) {
  21. return x; // expected-note{{instantiation}}
  22. }
  23. void test3(X<int> &x, X<int> xi, X<long> xl, X<int Y::*> xmptr) {
  24. x = xi;
  25. x = xl;
  26. x = xmptr; // expected-note{{instantiation}}
  27. }
  28. struct X1 {
  29. X1 &operator=(const X1&);
  30. };
  31. template<typename T>
  32. struct X2 : X1 {
  33. template<typename U> X2 &operator=(const U&);
  34. };
  35. struct X3 : X2<int> {
  36. };
  37. void test_X2(X3 &to, X3 from) {
  38. to = from;
  39. }