ErikasKontenis / SabrehavenServer

15 stars 34 forks source link

Fix ubuntu20+ compile "error" #1

Closed danilopucci closed 1 year ago

danilopucci commented 1 year ago

Fix description

catching exception with const& on BehaviourDatabase::searchDigitNoLimit

Fix info

The project is configured to compile with warning as errors (-Werror) it is failing to compile on ubuntu20+ with the following error

[  8%] Building CXX object CMakeFiles/tfs.dir/src/behaviourdatabase.cpp.o
SabrehavenServer/src/behaviourdatabase.cpp: In member function ‘int32_t BehaviourDatabase::searchDigitNoLimit(const string&)’:
SabrehavenServer/src/behaviourdatabase.cpp:1443:17: warning: catching polymorphic type ‘class std::invalid_argument’ by value [-Wcatch-value=]
 1443 |     catch (std::invalid_argument) {
      |                 ^~~~~~~~~~~~~~~~
SabrehavenServer/src/behaviourdatabase.cpp:1446:17: warning: catching polymorphic type ‘class std::out_of_range’ by value [-Wcatch-value=]
 1446 |     catch (std::out_of_range) {
      |                 ^~~~~~~~~~~~

An ungraceful solution is to remove the compile options flag -Werror and it will compile with the warning mentioned above. A better solution is by simple cataching exceptions with const&, since the catch-block is not modifying it