tschumann/sandbot

Compilation fails with a narrowing conversion error

Closed this issue · 4 comments

When I try to compile on Fedora with C++11, it throws the following error:

bot_combat.cpp: At global scope:
bot_combat.cpp:88:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
   88 | };
      | ^
bot_combat.cpp:156:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
  156 | };
      | ^
bot_combat.cpp:173:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
  173 | };
      | ^
bot_combat.cpp:243:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
  243 | };
      | ^
bot_combat.cpp:299:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
  299 | };
      | ^
bot_combat.cpp:340:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
  340 | };
      | ^
bot_combat.cpp:429:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
  429 | };
      | ^
bot_combat.cpp:501:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
  501 | };
      | ^
bot_combat.cpp:506:1: error: narrowing conversion of ‘0.0f’ from ‘float’ to ‘bool’ [-Wnarrowing]
  506 | };

It seems to be due to the fact that C++ doesn't narrow anymore. See https://www.stroustrup.com/C++11FAQ.html#narrowing
I'm not well versed in C++ so I could be wrong.

I'll take a look - I don't have the code handy but I'm guessing I've misaligned a struct declaration.
What version of gcc are you using?

I'll take a look - I don't have the code handy but I'm guessing I've misaligned a struct declaration.
What version of gcc are you using?

Wait @mathieuf20 is about to open a PR with a patch.

@dannycolin what version of gcc were you using?

I used gcc (GCC) 11.1.1 20210428