Skip to content

Clang warning: -Wstring-plus-int

Summary

When building with clang, one gets a -Wstring-plus-int warning in GEMGlobalState. The warning corresponds to a potential out-of-bounds array indexing.

Steps to reproduce

Configure with CC=clang CXX=clang++ cmake ... and build.

What is the expected correct behavior?

No -Wstring-plus-int warning.

Relevant logs and/or screenshots

[82/98] Building CXX object gemsupervisor/CMakeFiles/gemsupervisor.dir/src/GEMGlobalState.cpp.o
../gemsupervisor/src/GEMGlobalState.cpp:75:58: warning: adding 'toolbox::fsm::State' (aka 'char') to a string does not append to the string [-Wstring-plus-int]
        setGlobalStateMessage("Reached terminal state: " + m_globalState);
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
../gemsupervisor/src/GEMGlobalState.cpp:75:58: note: use array indexing to silence this warning
        setGlobalStateMessage("Reached terminal state: " + m_globalState);
                                                         ^
                              &                          [              ]
1 warning generated.

Environment

  • Version used: develop
  • Operation System: gem904daq04

Possible fixes

Wrap m_globalState into std::to_string. Add -Werror=-Wstring-plus-int because this warning usually finds real mistakes.