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

Fix: Compiler warnings about memsetting non-trivial classes #8241

Merged
merged 5 commits into from Jun 27, 2020

Conversation

LordAro
Copy link
Member

@LordAro LordAro commented Jun 27, 2020

Noticed a couple of warnings with GCC 10:

/home/lordaro/dev/openttd/src/network/network_gui.cpp: In member function ‘virtual void NetworkLobbyWindow::OnClick(Point, int, int)’:
/home/lordaro/dev/openttd/src/network/network_gui.cpp:1583:61: warning: ‘void* memset(void*, int, size_t)’ clearing an object of type ‘struct NetworkCompanyInfo’ with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
 1583 |     memset(this->company_info, 0, sizeof(this->company_info));
      |                                                             ^
In file included from /home/lordaro/dev/openttd/src/network/network_gui.cpp:15:
/home/lordaro/dev/openttd/src/network/network_gui.h:28:8: note: ‘struct NetworkCompanyInfo’ declared here
   28 | struct NetworkCompanyInfo : NetworkCompanyStats {
      |        ^~~~~~~~~~~~~~~~~~
/home/lordaro/dev/openttd/src/cargotype.cpp: In function ‘void SetupCargoForClimate(LandscapeID)’:
/home/lordaro/dev/openttd/src/cargotype.cpp:45:54: warning: ‘void* memset(void*, int, size_t)’ clearing an object of type ‘struct CargoSpec’ with no trivial copy-assignment; use assignment or value-initialization instead [-Wclass-memaccess]
   45 |  memset(CargoSpec::array, 0, sizeof(CargoSpec::array));
      |                                                      ^
In file included from /home/lordaro/dev/openttd/src/cargotype.cpp:11:
/home/lordaro/dev/openttd/src/cargotype.h:55:8: note: ‘struct CargoSpec’ declared here
   55 | struct CargoSpec {
      |        ^~~~~~~~~

michicc
michicc previously approved these changes Jun 27, 2020
Copy link
Member

@michicc michicc left a comment

Choose a reason for hiding this comment

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

Looks like the warning is because Money (aka OverflowSaveInt) has a default constructor.

It requires -O1 (or greater) and GCC spews out warnings if you try using it with -O0
@LordAro LordAro force-pushed the class-memaccess-warningfix branch from 0f16633 to 37faa87 Compare June 27, 2020 11:47
Copy link
Member

@michicc michicc left a comment

Choose a reason for hiding this comment

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

Not approving again 😈

@LordAro LordAro merged commit dc8d008 into OpenTTD:master Jun 27, 2020
@LordAro LordAro deleted the class-memaccess-warningfix branch June 27, 2020 13:51
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.

None yet

2 participants