Unable to set HTTPClient to a std::optional · Issue #8231 · esp8266/Arduino (original) (raw)
Basic Infos
- This issue complies with the issue POLICY doc.
- I have read the documentation at readthedocs and the issue is not addressed there.
- I have tested that the issue is present in current master branch (aka latest git).
- I have searched the issue tracker for a similar issue.
- If there is a stack dump, I have decoded it.
- I have filled out all fields below.
Platform
- Hardware: ESP-12
- Core Version: 3.0.1
- Development Env: Platformio
- Operating System: Ubuntu
Problem Description
We are unable to set a HTTPClient to a std::optional that already exists. I have no idea why, the compiler generates hundreds of lines of error all related to the fact that std::optional<HTTPClient>::operator=(std::optional<HTTPClient>&&)
is implicitly deleted. I have no idea how to make it work, nor am able to provide a PR to fix this (although I'm willing if pointed in the right direction). But this seems a bug. And is something we actually need (we memset the unused 4kb sys stack to zero and cast it to a struct that contains a bunch of classes, and the easier way to properly initialize them is to wrap them in an optional).
MCVE Sketch
#include <ESP8266HTTPClient.h> #include
void setup() { std::optional http; http = std::make_optional(HTTPClient()); }
void loop() {
}
Debug Messages
It's a huge compiler error (it's not from the example, it was extracted from our codebase, we were talking about this issue in the gitter chat): https://pastebin.com/2NZzvrgY
The core of it seems this:
include/loop.hpp:189:57: error: use of deleted function 'std::optional<HTTPClient>& std::optional<HTTPClient>::operator=(std::optional<HTTPClient>&&)'
189 | this->data->http = std::make_optional(HTTPClient());
.platformio/packages/toolchain-xtensa@2.100200.0/xtensa-lx106-elf/include/c++/10.2.0/optional:659:11: note: 'std::optional<HTTPClient>& std::optional<HTTPClient>::operator=(std::optional<HTTPClient>&&)' is implicitly deleted because the default definition would be ill-formed:
659 | class optional
| ^~~~~~~~
.platformio/packages/toolchain-xtensa@2.100200.0/xtensa-lx106-elf/include/c++/10.2.0/optional:659:11: error: use of deleted function 'std::_Enable_copy_move<false, false, false, false, _Tag>& std::_Enable_copy_move<false, false, false, false, _Tag>::operator=(std::_Enable_copy_move<false, false, false, false, _Tag>&&) [with _Tag = std::optional<HTTPClient>]'
.platformio/packages/toolchain-xtensa@2.100200.0/xtensa-lx106-elf/include/c++/10.2.0/bits/enable_special_members.h:306:5: note: declared here
306 | operator=(_Enable_copy_move&&) noexcept = delete;
.platformio/packages/toolchain-xtensa@2.100200.0/xtensa-lx106-elf/include/c++/10.2.0/optional: In instantiation of 'constexpr std::optional<typename std::decay<_Tp>::type> std::make_optional(_Tp&&) [with _Tp = HTTPClient; typename std::decay<_Tp>::type = std::decay<HTTPClient>::type]':
include/loop.hpp:189:57: required from here .platformio/packages/toolchain-xtensa@2.100200.0/xtensa-lx106-elf/include/c++/10.2.0/optional:1207:62: error: no matching function for call to 'std::optional<HTTPClient>::optional(<brace-enclosed initializer list>)'
1207 | { return optional<decay_t<_Tp>> { std::forward<_Tp>(__t) }; }
And it goes on and on.