Skip to content
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

WiFiClient copy constructor #8917

Closed
wants to merge 4 commits into from

Conversation

JAndrassy
Copy link
Contributor

WiFiClient has assignment operator defined and no copy constructor. Then I get a warning

implicitly-declared 'WiFiClient::WiFiClient(const WiFiClient&)' is deprecated [-Wdeprecated-copy]

on returning an existing client instance from a function as a return value.

This PR adds the copy constructor.

The copy-ability of implementations of the Client class is a feature of the 'Arduino language' to avoid use of pointers.

@SuGlider SuGlider self-assigned this Nov 26, 2023
@SuGlider SuGlider self-requested a review November 27, 2023 12:57
@VojtechBartoska VojtechBartoska added Area: WiFi Issue related to WiFi Status: Review needed Issue or PR is awaiting review labels Nov 28, 2023
@VojtechBartoska VojtechBartoska added this to the 3.0.0-RC1 milestone Nov 28, 2023
@SuGlider
Copy link
Collaborator

SuGlider commented Dec 1, 2023

@JAndrassy - I can't reproduce the message implicitly-declared 'WiFiClient::WiFiClient(const WiFiClient&)' is deprecated [-Wdeprecated-copy]. The complier should use the implicit copy constructor whenever necessary.

Please provide more information:

  • Arduino Core version used
  • Compiler Xtensa, Risc-V (SoC? ESP32, C3)
  • The simpler Sketch example that can reproduce the message.

Copy link
Collaborator

@SuGlider SuGlider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need more information about the use case that this PR solves.

@JAndrassy
Copy link
Contributor Author

at the second look, I see it would be better to remove the assignment operator. it should not stop() the client. some other copy may still want to work with that connection.

about the warning:

https://en.cppreference.com/w/cpp/language/rule_of_three

#include <WiFi.h>

WiFiClient client;

WiFiClient getClient() {
  return client;
}

void setup() {
}
void loop() {
}

image

@JAndrassy JAndrassy closed this Dec 1, 2023
@SuGlider
Copy link
Collaborator

SuGlider commented Dec 1, 2023

This is interesting... I'm using exactly the same IDE version and C3 with the same configuration.
But I get no error message.
The difference is that I'm using Windows 11.

@JAndrassy
Copy link
Contributor Author

JAndrassy commented Dec 1, 2023

But I get no error message.

maybe
image
in IDE Preferences?

I use Eclipse so I did the extra experiment in Arduino IDE to show the warning there

@JAndrassy JAndrassy deleted the wificlient_copy_ctor branch December 20, 2023 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: WiFi Issue related to WiFi Status: Review needed Issue or PR is awaiting review
Projects
Development

Successfully merging this pull request may close these issues.

3 participants