Skip to content

Fix warning about implicitly declared assignment operator - #316

Open
coldfix wants to merge 1 commit into
adafruit:masterfrom
defboard:fix-deprecated-copy
Open

coldfix wants to merge 1 commit into
adafruit:masterfrom
defboard:fix-deprecated-copy

Conversation

@coldfix

@coldfix coldfix commented Oct 7, 2025 •

Copy link
Copy Markdown

Hi,

this fixes a compiler warning when using the assignment operator on a DateTime object. The auto-generated DateTime& operator=(const DateTime&) is deprecated due to presence of a user provided copy constructor.

error: implicitly-declared 'constexpr DateTime& DateTime::operator=(const DateTime&)' is deprecated [-Werror=deprecated-copy]
  133 |     now = rtc.now();
      |                          ^~~~~~~~~~~~
/home/thomas/Arduino/libraries/RTClib/src/RTClib.h:148:3: note: because 'DateTime' has user-provided 'DateTime::DateTime(const DateTime&)'
  148 |   DateTime(const DateTime &copy);
      |   ^~~~~~~~

(here as error, because I am compiling with -Werror)

This PR solves the issue by removing the user-provided copy constructor, therefore using auto-generated copy constructor (which is identical anyway). In this case, there is no problem with also auto-generating the assignment operator.

I can change the PR to instead add a user-defined assignment operator if you prefer that approach.

Btw, thanks for the awesome library and all of the other modules!

Best, Thomas

@coldfix
coldfix force-pushed the fix-deprecated-copy branch from 3248958 to 83a2a65 Compare September 24, 2026 15:20

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant