ouster-lidar / ouster-sdk

Ouster, Inc. sample code
Other
468 stars 440 forks source link

Fix non-const string issue with C++20 #579

Closed kgreenek closed 3 months ago

kgreenek commented 8 months ago

Without this change, compiling with C++20 gives the following error due to the way std::string being used for the logging statement (which was not constexpr).

In file included from external/oustersdk/ouster_client/src/sensor_http_imp.cpp:3:
external/oustersdk/ouster_client/src/curl_client.h: In member function 'std::string CurlClient::execute_get(const string&, int, int) const':
external/oustersdk/ouster_client/src/curl_client.h:91:46: error: temporary of non-literal type 'std::__cxx11::basic_string<char>' in a constant expression
   91 |                 ouster::sensor::logger().warn(
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
   92 |                     std::string("Re-attempting CurlClient::execute_get after "
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   93 |                                 "failure for url: ") +
      |                                 ~~~~~~~~~~~~~~~~~~~~~~
   94 |                         "[{}] with the code: [{}] - and return: {}",
      |                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   95 |                     url, http_code, buffer);
      |                     ~~~~~~~~~~~~~~~~~~~~~~~   
In file included from /usr/include/c++/11/string:55,
                 from external/oustersdk/ouster_client/src/http_client.h:13,
                 from external/oustersdk/ouster_client/src/sensor_http_imp.h:12,
                 from external/oustersdk/ouster_client/src/sensor_http_imp.cpp:1:
/usr/include/c++/11/bits/basic_string.h:85:11: note: 'std::__cxx11::basic_string<char>' is not literal because:
   85 |     class basic_string
      |           ^~~~~~~~~~~~
/usr/include/c++/11/bits/basic_string.h:85:11: note:   'std::__cxx11::basic_string<char>' does not have 'constexpr' destructor
valgur commented 3 months ago

This has been fixed in the latest release and can be closed: https://github.com/ouster-lidar/ouster_example/blob/20240703/ouster_client/src/curl_client.h#L147-L148

kgreenek commented 3 months ago

Thank you!