self-assign.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // -*- mode: c++; coding: utf-8 -*-
  2. // ra-ra/test - Assign to expr from the same exact type. This bug was revealed by gcc 11.
  3. // (c) Daniel Llorens - 2021
  4. // This library is free software; you can redistribute it and/or modify it under
  5. // the terms of the GNU Lesser General Public License as published by the Free
  6. // Software Foundation; either version 3 of the License, or (at your option) any
  7. // later version.
  8. #include <vector>
  9. #include <iostream>
  10. #include "ra/test.hh"
  11. using std::cout, std::endl;
  12. int main()
  13. {
  14. ra::TestRecorder tr(std::cout);
  15. {
  16. ra::Big<int, 2> C = {{0, 0, 0, 0}, {0, 9, 0, 0}, {0, 0, 9, 0}, {0, 0, 0, 0}};
  17. ra::Big<int, 2> A({4, 4}, 0), B({4, 4}, 9);
  18. using coord = ra::Small<int, 2>;
  19. ra::Big<coord, 1> I = { {1, 1}, {2, 2} };
  20. at(A, I) = 9;
  21. tr.test_eq(C, A);
  22. A = 0;
  23. at(A, I) = at(B, I);
  24. tr.test_eq(C, A);
  25. }
  26. {
  27. ra::Big<int, 2> A({4, 4}, 4);
  28. ra::Big<int, 2> B({4, 4}, 8);
  29. ra::Big<int, 2> C({4, 4}, 2);
  30. ra::Big<int, 2> D({4, 4}, 0);
  31. ra::Big<int, 1> s = { 0, 1, 0, 1 };
  32. ra::Big<int, 1> z = { 1, 0, 0, 1 };
  33. pick(s, A, B) = pick(z, C, D); // A(0)=D(0); B(1)=C(1); A(2)=C(2); B(3)=D(3);
  34. tr.test_eq(A, ra::Big<int, 2> {{0, 0, 0, 0}, {4, 4, 4, 4}, {2, 2, 2, 2}, {4, 4, 4, 4}});
  35. tr.test_eq(B, ra::Big<int, 2> {{8, 8, 8, 8}, {2, 2, 2, 2}, {8, 8, 8, 8}, {0, 0, 0, 0}});
  36. }
  37. return tr.summary();
  38. }