ra-8.C 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // -*- mode: c++; coding: utf-8 -*-
  2. /// @file ra-8.C
  3. /// @brief Regression test for lvalue exprs in gcc 6.1
  4. // (c) Daniel Llorens - 2016
  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. // Failed for Expr:: Ryn:: Vector:: =, += ... on gcc 6.1 due to bug 70942. This
  10. // is kept to show why that forward<decltype(y)>(y) is there.
  11. #include <iostream>
  12. #include <iterator>
  13. #include "ra/mpdebug.H"
  14. #include "ra/complex.H"
  15. #include "ra/format.H"
  16. #include "ra/test.H"
  17. #include "ra/big.H"
  18. #include "ra/operators.H"
  19. #include "ra/io.H"
  20. using std::cout, std::endl, std::flush, std::tuple;
  21. using real = double;
  22. template <int rank=ra::RANK_ANY> using Ureal = ra::Unique<real, rank>;
  23. template <int rank=ra::RANK_ANY> using Uint = ra::Unique<int, rank>;
  24. int main()
  25. {
  26. TestRecorder tr(std::cout);
  27. // tr.section("gcc 6.1 A");
  28. // {
  29. // // Both must be lvalues [ra05]. FIXME check that these fail [ra42]
  30. // ra::Unique<int, 1> a { 0, 0, 0, 0 };
  31. // ra::Unique<int, 1> b { 0, 0, 0, 0 };
  32. // where(ra::_0>0 && ra::_0<3, ra::_0, a) = 99;
  33. // where(ra::_0>0 && ra::_0<3, a, ra::_0) = 99;
  34. // }
  35. tr.section("gcc 6.1 B");
  36. {
  37. Ureal<1> a {1, 4, 2, 3};
  38. Ureal<1> b({4}, 0.);
  39. b(3-ra::_0) = a;
  40. tr.test_eq(Ureal<1> {3, 2, 4, 1}, b);
  41. }
  42. tr.section("gcc 6.1 C");
  43. {
  44. Ureal<1> a = {1, 2, 3, 4};
  45. Uint<1> i = {3, 1, 2};
  46. a(i) = ra::Unique<real, 1> {7, 8, 9};
  47. tr.test_eq(a, Ureal<1> {1, 8, 9, 7});
  48. }
  49. tr.section("gcc 6.1 D");
  50. {
  51. ra::Big<int, 2> A({4, 4}, 0), B({4, 4}, 10*ra::_0 + ra::_1);
  52. using coord = ra::Small<int, 2>;
  53. ra::Big<coord, 1> I = { coord{1, 1}, coord{2, 2} };
  54. map([&A](auto && c) -> decltype(auto) { return A.at(c); }, I)
  55. = map([&B](auto && c) { return B.at(c); }, I);
  56. tr.test_eq(Ureal<2>({4, 4}, {0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 22, 0, 0, 0, 0, 0}), A);
  57. }
  58. return tr.summary();
  59. }