afritz1 / OpenTESArena

Open-source re-implementation of The Elder Scrolls: Arena.
MIT License
915 stars 68 forks source link

lambda parameter ‘miscAssets’ previously declared as a capture (World/ProvinceDefinition.cpp) #176

Closed GregTheMadMonk closed 4 years ago

GregTheMadMonk commented 4 years ago

When compiling OpenTESArena, compiler throws an error:

/home/greg/projects/cpp/OpenTESArena/OpenTESArena/src/World/ProvinceDefinition.cpp:29:68: error: lambda parameter ‘miscAssets’ previously declared as a capture
   29 |   LocationDefinition::CityDefinition::Type type, const MiscAssets &miscAssets)

The lines that cause the error: https://github.com/afritz1/OpenTESArena/blob/c45335ddfdb2bdac7ecf7f1603dbdbd27d63faf6/OpenTESArena/src/World/ProvinceDefinition.cpp#L27-L29 According to this StackOverflow answer, even if the code compiled, it would've used the parameter miscAssets, not the captured one. As expected, when miscAssets is removed from capture list, game compiles and runs. The other way around this issue is removing const MiscAssets &miscAssets from lambda parameters, and removing an extra parameter in call https://github.com/afritz1/OpenTESArena/blob/c45335ddfdb2bdac7ecf7f1603dbdbd27d63faf6/OpenTESArena/src/World/ProvinceDefinition.cpp#L83 as it seems to be the only place that calls tryAddCity and miscAssets captured there is the same as captured in tryAddCity. This solution also leads to the game compiling and running.

My gcc --version: gcc (Arch Linux 9.3.0-1) 9.3.0

Sorry if my english is hard to understand sometimes)

afritz1 commented 4 years ago

That was a minor derp on my part. It should probably use the captured miscAssets instead. I'll make a fix soon.

afritz1 commented 4 years ago

Should be fixed in commit 1d244cb4b0473a8de6dbdfb86d02d9e5615225c9. Strangely Travis CI didn't complain about it in the first place.

GregTheMadMonk commented 4 years ago

Yup, it helped.