From: Alexey Spiridonov Date: Mon, 27 Jul 2015 02:36:57 +0000 (-0700) Subject: Make ProcessReturnCode default-constructible X-Git-Tag: v0.52.0~1 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=3f277b37615ce99eeb38e21922053c8b4c8ba2db Make ProcessReturnCode default-constructible Summary: We have this previously-unused "NOT STARTED" status, which I recently appropriated to denote moved-out `ProcessReturnCode`s. It's natural to also use this for default-constructed `ProcessReturnCodes`. Lacking a default constructor leads to a bunch of unnecessarily annoying use of `folly::Optional` in my upcoming diff, so I wanted to get rid of that, see e.g. differential/diff/7657906/ Reviewed By: @tudor Differential Revision: D2097368 --- diff --git a/folly/Subprocess.h b/folly/Subprocess.h index 0354b4b2..4f970082 100644 --- a/folly/Subprocess.h +++ b/folly/Subprocess.h @@ -126,12 +126,18 @@ class ProcessReturnCode { friend class Subprocess; public: enum State { + // Subprocess starts in the constructor, so this state designates only + // default-initialized or moved-out ProcessReturnCodes. NOT_STARTED, RUNNING, EXITED, KILLED }; + // Default-initialized for convenience. Subprocess::returnCode() will + // never produce this value. + ProcessReturnCode() : ProcessReturnCode(RV_NOT_STARTED) {} + // Trivially copyable ProcessReturnCode(const ProcessReturnCode& p) = default; ProcessReturnCode& operator=(const ProcessReturnCode& p) = default; diff --git a/folly/test/SubprocessTest.cpp b/folly/test/SubprocessTest.cpp index b42a0d57..724dbd24 100644 --- a/folly/test/SubprocessTest.cpp +++ b/folly/test/SubprocessTest.cpp @@ -56,6 +56,11 @@ TEST(SimpleSubprocessTest, ExitsWithErrorChecked) { EXPECT_THROW(proc.waitChecked(), CalledProcessError); } +TEST(SimpleSubprocessTest, DefaultConstructibleProcessReturnCode) { + ProcessReturnCode retcode; + EXPECT_TRUE(retcode.notStarted()); +} + TEST(SimpleSubprocessTest, MoveSubprocess) { Subprocess old_proc(std::vector{ "/bin/true" }); EXPECT_TRUE(old_proc.returnCode().running());