I would like to use Boost::Process::Child to create a process while also supplying an environment variable to that process. While it seems straightforward, I've also got the requirement of compiling with -Wall -Wextra -pedantic -Werror -Wl,--fatal-warnings
(Basically, the slightest issue is treated as an error).
I'm following the Boost tutorial (https://www.boost.org/doc/libs/1_80_0/doc/html/boost_process/tutorial.html#boost_process.tutorial.env) and the answer in a duplicate question here: Create child process with custom environment using boost for something similar to this:
std::string command = "/usr/bin/something";
ipstream pipe_stream;
auto env = boost::this_process::environment();
env["SOMETHING"] = "VALUE";
boost::process::child childProc(command, env, std_out > pipe_stream);
This works until I add my compiler switches. Now I'm getting an error:
/usr/lib/boost/boost/process/env.hpp:309:13: error: implicitly-declared 'boost::process::basic_environment<char>& boost::process::basic_environment<char>::operator=(const boost::process::basic_environment<char>&)' is deprecated [-Werror=deprecated-copy]
309 | env = e;
| ~~~~^~~
And some additional notes:
/usr/lib/boost/boost/process/detail/posix/environment.hpp:177:30: note: because 'boost::process::basic_environment<char>' has user-provided 'boost::process::detail::posix::basic_environment_impl<Char>& boost::process::detail::posix::basic_environment_impl<Char>::operator=(const boost::process::detail::posix::basic_environment_impl<Char>&) [with Char = char]'
177 | basic_environment_impl & operator=(const basic_environment_impl& rhs)
| ^~~~~~~~
/usr/lib/boost/boost/process/env.hpp:309:13: note: synthesized method 'boost::process::basic_environment<char>& boost::process::basic_environment<char>::operator=(const boost::process::basic_environment<char>&)' first required here
309 | env = e;
| ~~~~^~~
It seems the boost::process::child constructor uses a now-deprecated basic_environment copy constructor, but the documentation still shows this as the appropriate method.
How do I construct a boost::process::child with an environment now without this warning/error?