Remove folly::Future conversion constructor
authorNick Wolchko <nwolchko@fb.com>
Mon, 9 Jan 2017 17:20:48 +0000 (09:20 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Mon, 9 Jan 2017 17:33:03 +0000 (09:33 -0800)
commit22d54e0b866b19b74e6b37b27f284b55e0c9205f
tree7c1202c76256fd363387ab646518f24fd994ed0f
parent05d3945f70faeed41a24a801c9703ad8397fc0cb
Remove folly::Future conversion constructor

Summary:
This constructor is unsafe. The check it uses before doing the comparison isn't a safe enough check to see if the cast is valid. For example, this is broken in the presence of multiple inheritance because it doesn't adjust the pointer offset to the correct vtable.

e.g.
  struct A {
    virtual ~A() {};
    virtual void doSomething() = 0;
  };
  struct B {
    virtual ~B() {}
    virtual void doSomethingElse() = 0;
  };
  struct C : public B, public A {
    virtual ~C() {}
    void doSomething() override {
      std::cout << "Something!" << std::endl;
    }
    void doSomethingElse() override {
      std::cout << "Something Else!" << std::endl;
    }
  };
  int main (int argc, char **argv) {
    auto c = folly::makeFuture<std::shared_ptr<C>>(std::make_shared<C>());
    folly::Future<std::shared_ptr<A>> a = std::move(c);
    a.get()->doSomething();
    return 0;
  }
This code will print "Something else!" when run.

Reviewed By: siyengar

Differential Revision: D3679673

fbshipit-source-id: dcbf40ca82d458f17ee11191591f8b8daf58c919
folly/futures/Future-inl.h
folly/futures/Future.h
folly/futures/detail/Core.h
folly/futures/test/ConversionTest.cpp [deleted file]
folly/test/Makefile.am