self-assign.cc 1.5 KB

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