jsonrpcx/json-rpc-cxx

compile error in test/server.cpp class TestServer method dirty_method()

linuxlizard opened this issue · 1 comments

/home/dpoole/src/json-rpc-cxx/test/server.cpp: In member function ‘int TestServer::dirty_method(int, int)’:
/home/dpoole/src/json-rpc-cxx/test/server.cpp:98:45: error: ignoring return value of ‘std::string std::__cxx11::to_string(int)’, declared with attribute ‘nodiscard’ [-Werror=unused-result]
   98 |   int dirty_method(int a, int b) { to_string(a+b); throw std::exception(); }
      |                                    ~~~~~~~~~^~~~~
In file included from /usr/include/c++/14/string:54,                           
                 from /usr/include/c++/14/bits/locale_classes.h:40, 
                 from /usr/include/c++/14/bits/ios_base.h:41,                  
                 from /usr/include/c++/14/streambuf:43,             
                 from /usr/include/c++/14/bits/streambuf_iterator.h:35,
                 from /usr/include/c++/14/iterator:66,
                 from /home/dpoole/src/json-rpc-cxx/vendor/nlohmann/json.hpp:53,
                 from /home/dpoole/src/json-rpc-cxx/include/jsonrpccxx/common.hpp:2,
                 from /home/dpoole/src/json-rpc-cxx/include/jsonrpccxx/server.hpp:3,
                 from /home/dpoole/src/json-rpc-cxx/test/testserverconnector.hpp:3,
                 from /home/dpoole/src/json-rpc-cxx/test/server.cpp:2:
/usr/include/c++/14/bits/basic_string.h:4240:3: note: declared here
 4240 |   to_string(int __val)                                                 
      |   ^~~~~~~~~                                                            
cc1plus: all warnings being treated as errors                          
make[2]: *** [CMakeFiles/jsonrpccpp-test.dir/build.make:132: CMakeFiles/jsonrpccpp-test.dir/test/server.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/jsonrpccpp-test.dir/all] Error 2
make: *** [Makefile:146: all] Error 2 

Fedora Linux 40 (Workstation Edition)
gcc (GCC) 14.1.1 20240620 (Red Hat 14.1.1-6)
GNU libc version: 2.39

std::to_string() is marked nodiscard so the test code:
int dirty_method(int a, int b) { to_string(a+b); throw std::exception(); }

needs to capture the return.

PR incoming.

Thanks!