afritz1/OpenTESArena

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

Closed this issue · 3 comments

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:

auto tryAddCity = [this, &miscAssets, &provinceData, &canAddLocation](int localCityID,
int provinceID, bool coastal, bool premade,
LocationDefinition::CityDefinition::Type type, const MiscAssets &miscAssets)

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
tryAddCity(localCityID, provinceID, coastal, premade, type, miscAssets);

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)

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

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

Yup, it helped.