SICKAG / libsick_ldmrs

This package contains a library for communicating with the SICK LD-MRS line of laser scanners. For a ROS wrapper, see sick_ldmrs_laser.
Apache License 2.0
7 stars 18 forks source link

Compiler warning #7

Closed rostest closed 2 years ago

rostest commented 2 years ago

First of all, thanks for your ldmrs support! I got the following compiler warning using C++17 and ROS-2 humble:

/workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp: In member function ‘bool devices::SopasBase::action_getScannerTypeAndVersion()’:
/workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp:1557:28: warning: ignoring return value of ‘bool std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::empty() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’, declared with attribute ‘nodiscard’ [-Wunused-result]
 1557 |         m_scannerName.empty();
      |         ~~~~~~~~~~~~~~~~~~~^~
In file included from /usr/include/c++/11/string:55,
                 from /workspace/src/libsick_ldmrs/src/sopas/../BasicDatatypes.hpp:17,
                 from /workspace/src/libsick_ldmrs/src/sopas/SopasBase.hpp:11,
                 from /workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp:8:
/usr/include/c++/11/bits/basic_string.h:1023:7: note: declared here
 1023 |       empty() const _GLIBCXX_NOEXCEPT
      |       ^~~~~
/workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp:1558:31: warning: ignoring return value of ‘bool std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::empty() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’, declared with attribute ‘nodiscard’ [-Wunused-result]
 1558 |         m_scannerVersion.empty();
      |         ~~~~~~~~~~~~~~~~~~~~~~^~
In file included from /usr/include/c++/11/string:55,
                 from /workspace/src/libsick_ldmrs/src/sopas/../BasicDatatypes.hpp:17,
                 from /workspace/src/libsick_ldmrs/src/sopas/SopasBase.hpp:11,
                 from /workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp:8:
/usr/include/c++/11/bits/basic_string.h:1023:7: note: declared here
 1023 |       empty() const _GLIBCXX_NOEXCEPT
      |       ^~~~~
/workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp: In member function ‘bool devices::SopasBase::action_getScannerTypeAndVersion()’:
/workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp:1557:28: warning: ignoring return value of ‘bool std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::empty() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’, declared with attribute ‘nodiscard’ [-Wunused-result]
 1557 |         m_scannerName.empty();
      |         ~~~~~~~~~~~~~~~~~~~^~
In file included from /usr/include/c++/11/string:55,
                 from /workspace/src/libsick_ldmrs/src/sopas/../BasicDatatypes.hpp:17,
                 from /workspace/src/libsick_ldmrs/src/sopas/SopasBase.hpp:11,
                 from /workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp:8:
/usr/include/c++/11/bits/basic_string.h:1023:7: note: declared here
 1023 |       empty() const _GLIBCXX_NOEXCEPT
      |       ^~~~~
/workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp:1558:31: warning: ignoring return value of ‘bool std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::empty() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’, declared with attribute ‘nodiscard’ [-Wunused-result]
 1558 |         m_scannerVersion.empty();
      |         ~~~~~~~~~~~~~~~~~~~~~~^~
In file included from /usr/include/c++/11/string:55,
                 from /workspace/src/libsick_ldmrs/src/sopas/../BasicDatatypes.hpp:17,
                 from /workspace/src/libsick_ldmrs/src/sopas/SopasBase.hpp:11,
                 from /workspace/src/libsick_ldmrs/src/sopas/SopasBase.cpp:8:
/usr/include/c++/11/bits/basic_string.h:1023:7: note: declared here
 1023 |       empty() const _GLIBCXX_NOEXCEPT
      |       ^~~~~

The pull request just fixes the compiler warning by changing SopasBase.cpp lines 1557 and 1558 to

    // Clear old data.
    m_scannerName.clear(); // m_scannerName.empty();
    m_scannerVersion.clear(); // m_scannerVersion.empty();
mintar commented 2 years ago

There's so many things wrong with that code... (not with your PR, but with that existing snippet of code). But your fix clearly makes the code do what the author intended, so I'm merging it!

P.S.: Next time, it's better to split whitespace fixes and actual changes into two separate commits. This makes spotting the real changes, rebasing etc. easier.