Skip to content

Conversation

@coldfix
Copy link

@coldfix coldfix commented Oct 7, 2025

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

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