From b1d75fe48c940ba677614db3d891fbebcb8a41a2 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Mon, 19 Aug 2024 15:16:04 +0000 Subject: [PATCH] [lldb][test] Fix cast dropping const warnin in TestBreakpointSetCallback.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When building with gcc I get this warning: ``` <...>TestBreakpointSetCallback.cpp:58:25: warning: cast from type ‘const char*’ to type ‘void*’ casts away qualifiers [-Wcast-qual] 58 | void *baton = (void *)"hello"; | ^~~~~~~ ``` Use the address of a mutable global variable instead. All we care about is that the address passed as the baton is the same one we get later. --- lldb/unittests/Callback/TestBreakpointSetCallback.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp index 2a7070f9349c..3dba4a9eb719 100644 --- a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp +++ b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp @@ -30,6 +30,8 @@ using namespace lldb; static constexpr lldb::user_id_t expected_breakpoint_id = 1; static constexpr lldb::user_id_t expected_breakpoint_location_id = 0; +int baton_value; + class BreakpointSetCallbackTest : public ::testing::Test { public: static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context, @@ -37,7 +39,7 @@ public: lldb::user_id_t break_loc_id, TargetSP expected_target_sp) { EXPECT_EQ(context->exe_ctx_ref.GetTargetSP(), expected_target_sp); - EXPECT_EQ(baton, "hello"); + EXPECT_EQ(baton, &baton_value); EXPECT_EQ(break_id, expected_breakpoint_id); EXPECT_EQ(break_loc_id, expected_breakpoint_location_id); } @@ -55,7 +57,6 @@ protected: }; TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) { - void *baton = (void *)"hello"; // Set up the debugger, make sure that was done properly. TargetSP target_sp; ArchSpec arch("x86_64-apple-macosx-"); @@ -78,7 +79,7 @@ TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) { CheckCallbackArgs(baton, context, break_id, break_loc_id, target_sp); return true; }, - baton, true); + (void *)&baton_value, true); ExecutionContext exe_ctx(target_sp, false); StoppointCallbackContext context(nullptr, exe_ctx, true); breakpoint_sp->InvokeCallback(&context, 0);