Le 07/06/2016 15:05, Jean-Marc Lasgouttes a écrit :
Le 07/06/2016 à 09:04, Jean-Marc Lasgouttes a écrit :
Le 05/06/2016 01:01, Guillaume Munch a écrit :
12. This is a new helper class that I wrote because the Changer class
from MetricsInfo was too cumbersome (essentially a TeX \def with
shadowing). This commit entirely replaces the latter with a better
alternative. While I am not sure that the Changer mechanism itself is
the best practice, this is the best solution in the context it is used,
given the current architecture of painting (I have found uses outside of
painting as well too). Since this is used in all the metrics and
painting mechanism, comments are kindly requested before committing.

I would not pretend that I understand everything here, but having a
general Changer system is something I have been wanting to do for some
time. I think this is OK.

Now that I tried to compile, I can see clang complain:

My old clang 3.0 dies as follow, and clang 3.7 does approximately the same.

JMarc

Try changing 'return rc;' to 'return std::move(rc);' (twice).

I believe clang is right and gcc is wrong. gcc treats rc as an rvalue,
which makes the conversion into unique_ptr<Revertible> valid. But rc
should not be considered as an rvalue, because the standard only allows
the case when the return type matches the type of the expression (up
to cv-qualifiers).

You can test the following code:

  #include <iostream>
  struct D {};
  struct C {
        C(D &&) { std::cout << "Wrong!\n"; }
        C(D const &) { std::cout << "Correct!\n"; }
  };
  C f() { D x = D(); return x; }
  int main (int, char **) { C x = f(); return 0; }

gcc 5.3.1 gives "Wrong!" whereas clang 3.8 gives "Correct!".


(There's even worse. The following program:

  #include <iostream>
  struct D {
        int i;
        D(int i) : i(i) {};
  };
  struct C {
        int i;
        C(D && x) : i(x.i)  { std::cout << "Wrong!\n"; }
        C(D x) : i(x.i) { std::cout << "Correct!\n"; }
  };
  C f() {
        D x = D(14814);
        return x;
        std::cout << "What am I doing here?? ";
  }
  int main (int, char **)
  {
        C x = f();
        std::cout << x.i;
        return 0;
  }

gives me: "What am I doing here?? 6295648")

Thanks for the tests.

Reply via email to