Unable to set HTTPClient to a std::optional · Issue #8231 · esp8266/Arduino (original) (raw)

Basic Infos

Platform

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.