Page MenuHomeWildfire Games

Fix Pathfinder Grid.h compiler warning
ClosedPublic

Authored by elexis on Jul 19 2019, 12:31 AM.

Details

Summary

With gcc 8 and later there is a compiler warning for Grid.h:

In file included from ../../../source/simulation2/helpers/Pathfinding.h:26,
                 from ../../../source/simulation2/helpers/LongPathfinder.h:21,
                 from ../../../source/simulation2/helpers/LongPathfinder.cpp:20:
../../../source/simulation2/helpers/Grid.h: In instantiation of ‘T* SparseGrid<T>::GetBucket(int, int) [with T = PathfindTile]’:
../../../source/simulation2/helpers/Grid.h:238:10:   required from ‘T& SparseGrid<T>::get(int, int) [with T = PathfindTile]’
../../../source/simulation2/helpers/LongPathfinder.cpp:406:41:   required from here
../../../source/simulation2/helpers/Grid.h:194:10: warning: ‘void* memset(void*, int, size_t)’ clearing an object of non-trivial type ‘struct PathfindTile’; use assignment or value-initialization instead [-Wclass-memaccess]
    memset(m_Data[b], 0, BucketSize*BucketSize*sizeof(T));
    ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../../../source/simulation2/helpers/LongPathfinder.cpp:20:
../../../source/simulation2/helpers/LongPathfinder.h:63:8: note: ‘struct PathfindTile’ declared here
 struct PathfindTile
        ^~~~~~~~~~~~
Test Plan

Verify that this works for both T=bool and T=PathfindTile. The latter is a struct. It must be initialized (not doing so will result in a segfault when ordering a unit to move).

One of them is used in LongPathfinder::ComputeJPSPath, the other is used in FillTerrain by atlas (tool filling the terrain with that texture).

Find out whether I have any idea what I'm doing here.

Diff Detail

Repository
rP 0 A.D. Public Repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

elexis updated this revision to Diff 8986.Jul 19 2019, 12:31 AM
elexis created this revision.

Exclude wrong local diff

elexis updated the Trac tickets for this revision.Jul 19 2019, 12:32 AM

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...

source/lobby/glooxwrapper/glooxwrapper.h
|  88| namespace·glooxwrapper
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'namespaceglooxwrapper{' is invalid C code. Use --std or --language to configure the language.

source/network/scripting/JSInterface_Network.cpp
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/network/StunClient.cpp
|   1| /*·Copyright·(C)·2017·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2017"

source/simulation2/helpers/Grid.h
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/simulation2/helpers/Grid.h
|  34| template<typename·T>
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'template<...' is invalid C code. Use --std or --language to configure the language.

source/network/StunClient.h
|   1| /*·Copyright·(C)·2017·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2017"

source/network/StunClient.h
|  26| namespace·StunClient
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'namespaceStunClient{' is invalid C code. Use --std or --language to configure the language.

source/lobby/IXmppClient.h
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/lobby/IXmppClient.h
|  24| namespace·StunClient·{
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'namespaceStunClient{' is invalid C code. Use --std or --language to configure the language.

source/lobby/XmppClient.cpp
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/network/tests/test_Net.h
|   1| /*·Copyright·(C)·2017·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2017"

source/network/tests/test_Net.h
|  37| class·TestNetComms·:·public·CxxTest::TestSuite
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classTestNetComms:' is invalid C code. Use --std or --language to configure the language.

source/lobby/XmppClient.h
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/lobby/XmppClient.h
|  24| 
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'namespaceStunClient{' is invalid C code. Use --std or --language to configure the language.

source/network/NetClient.h
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/network/NetClient.h
|  59| class·CNetClient·:·public·CFsm
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'classCNetClient:' is invalid C code. Use --std or --language to configure the language.
Executing section JS...
|    | [NORMAL] ESLintBear (indent):
|    | Expected indentation of 2 tabs but found 3.
|----|    | /zpool0/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js
|    |++++| /zpool0/trunk/binaries/data/mods/public/gui/gamesetup_mp/gamesetup_mp.js
| 210| 210| 				error("Unrecognised net message type: " + message.type);
| 211| 211| 			}
| 212| 212| 		else
| 213|    |-			// Not rejoining - just trying to connect to server
|    | 213|+		// Not rejoining - just trying to connect to server
| 214| 214| 
| 215| 215| 			switch (message.type)
| 216| 216| 			{
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/129/display/redirect

Successful build - Chance fights ever on the side of the prudent.

Linter detected issues:
Executing section Source...

source/simulation2/helpers/Grid.h
|   1| /*·Copyright·(C)·2018·Wildfire·Games.
|    | [NORMAL] LicenseYearBear:
|    | License should have "2019" year instead of "2018"

source/simulation2/helpers/Grid.h
|  34| template<typename·T>
|    | [MAJOR] CPPCheckBear (syntaxError):
|    | Code 'template<...' is invalid C code. Use --std or --language to configure the language.
Executing section JS...
Executing section cli...

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/130/display/redirect

historic_bruno accepted this revision.Jul 19 2019, 1:41 AM
This revision is now accepted and ready to land.Jul 19 2019, 1:41 AM
wraitii accepted this revision.Jul 19 2019, 7:12 AM
wraitii added a subscriber: wraitii.

This ought to work correctly, calling new U() value-initialises it, and this should set pointer to nullptr and integers to 0.
https://en.cppreference.com/w/cpp/language/value_initialization

Thanks for the reviews historic_bruno and wraitii!
This message had been bothering me since years.
There are more -Wclass-memaccess warnings, but I will address these independently.

source/simulation2/helpers/Grid.h
1 ↗(On Diff #8986)

(9)

195 ↗(On Diff #8986)

(unneeded braces)

This revision was automatically updated to reflect the committed changes.
Owners added a subscriber: Restricted Owners Package.Jul 19 2019, 2:52 PM