-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to set HTTPClient to a std::optional #8231
Comments
I tried with g++11 and the message is short and different:
|
No I haven't, I can do that tonight. But why should it be implicitly deleted? I'm not that keen on rules on default move constructors. |
Quoting earlier gitter thread: https://gitter.im/esp8266/Arduino?at=60f7e54a7331d202b5c10f43
and also referencing https://en.cppreference.com/w/cpp/language/default_constructor and https://en.cppreference.com/w/cpp/language/move_assignment, you must implement constructors and assignment operators yourself if compiler can't do it for you. For the above, HTTPClient is cannot pass the HTTPClient::HTTPClient(HTTPClient&&); HTTPClient& HTTPClient::operator=(HTTPClient&&); My earlier suggestion was to also look at WifiClient, since it can't (?) be moved properly. There are issues with ClientContext* member deleting itself though, but that's whole other can of worms edit: read as - cannot be moved with =default and needs explicit |
Done! |
- =default for default ctor, destructor, move ctor and the assignment move - use `std::unique_ptr<WiFiClient>` instead of raw pointer to the client - implement `virtual std::unique_ptr<WiFiClient> WiFiClient::clone()` to safely copy the WiFiClientSecure instance, without accidentally slicing it (i.e. using the pointer with incorrect type, calling base WiFiClient virtual methods) - replace headers pointer array with `std::unique_ptr<T[]>` to simplify the move operations - substitute userAgent with the default one when it is empty (may be a subject to change though, b/c now there is a global static `String`) Allow HTTPClient to be placed inside of movable classes (e.g. std::optional, requested in the linked issue) or to be returned from functions. Class logic stays as-is, only the underlying member types are changed. Notice that WiFiClient connection object is now copied, and the internal ClientContext will be preserved even after the original WiFiClient object was destroyed. replaces #8236 resolves #8231 and, possibly #5734
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
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:
And it goes on and on.
The text was updated successfully, but these errors were encountered: