Skip to content

Unnecessary cast warnings when compiling tests with option -Wuseless-cast#4711

Open
siddux wants to merge 1 commit intogoogle:mainfrom
siddux:patch/useless_cast_warning
Open

Unnecessary cast warnings when compiling tests with option -Wuseless-cast#4711
siddux wants to merge 1 commit intogoogle:mainfrom
siddux:patch/useless_cast_warning

Conversation

@siddux
Copy link
Copy Markdown

@siddux siddux commented Jan 30, 2025

I've found some warnings when compiling my tests using the -Wuseless-cast flag. The proposed changes seems to fix it.

--- stderr: robot_health_checker                                                                                                                                              
In file included from /opt/ros/humble/src/gtest_vendor/./src/gtest.cc:122,
                 from /opt/ros/humble/src/gtest_vendor/src/gtest-all.cc:41:
/opt/ros/humble/src/gtest_vendor/./src/gtest-internal-inl.h: In member function ‘virtual void testing::internal::StreamingListener::SocketWriter::Send(const string&)’:
/opt/ros/humble/src/gtest_vendor/./src/gtest-internal-inl.h:1091:24: warning: useless cast to type ‘size_t’ {aka ‘long unsigned int’} [-Wuseless-cast]
 1091 |       const auto len = static_cast<size_t>(message.length());
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /opt/ros/humble/src/gtest_vendor/src/gtest-all.cc:41:
/opt/ros/humble/src/gtest_vendor/./src/gtest.cc: In member function ‘std::string testing::internal::UnitTestImpl::CurrentOsStackTraceExceptTop(int)’:
/opt/ros/humble/src/gtest_vendor/./src/gtest.cc:821:7: warning: useless cast to type ‘int’ [-Wuseless-cast]
  821 |       static_cast<int>(GTEST_FLAG(stack_trace_depth)),
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/ros/humble/src/gtest_vendor/./src/gtest.cc: In static member function ‘static void testing::internal::XmlUnitTestResultPrinter::OutputXmlCDataSection(std::ostream*, const char*)’:
/opt/ros/humble/src/gtest_vendor/./src/gtest.cc:3754:20: warning: useless cast to type ‘std::streamsize’ {aka ‘long int’} [-Wuseless-cast]
 3754 |           segment, static_cast<std::streamsize>(next_segment - segment));
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Jan 30, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants