From: Andrei Alexandrescu Date: Wed, 4 Feb 2015 19:57:51 +0000 (-0800) Subject: Disallow assignment to rvalue Range objects (and StringPiece in particular) X-Git-Tag: v0.25.0~17 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=7eaace048e3925a712e6a39c2e3d91e32b0cdc9a;p=folly.git Disallow assignment to rvalue Range objects (and StringPiece in particular) Summary: Before this diff the code below compiled and did absolutely nothing of interest: StringPiece fun(); ... fun() = "hello"; i.e. assignment to an rvalue range was allowed. Such code is almost always, if not always, in error. This diff fixes that. Test Plan: ran unittests Reviewed By: ldbrandy@fb.com Subscribers: mpawlowski, net-systems@, folly-diffs@, yfeldblum FB internal diff: D1825360 Signature: t1:1825360:1423097817:fdaaf893cd1abbe71dc857a315df7c45cb6a0bd0 --- diff --git a/folly/Range.h b/folly/Range.h index 1d904faf..da27ac61 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -184,6 +184,9 @@ public: constexpr Range() : b_(), e_() { } + constexpr Range(const Range&) = default; + constexpr Range(Range&&) = default; + public: // Works for all iterators constexpr Range(Iter start, Iter end) : b_(start), e_(end) { @@ -322,6 +325,9 @@ public: e_(other.end()) { } + Range& operator=(const Range& rhs) & = default; + Range& operator=(Range&& rhs) & = default; + void clear() { b_ = Iter(); e_ = Iter();