Skip to content

Commit b1d75fe

Browse files
committed
[lldb][test] Fix cast dropping const warnin in TestBreakpointSetCallback.cpp
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.
1 parent b64e7e0 commit b1d75fe

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lldb/unittests/Callback/TestBreakpointSetCallback.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@ using namespace lldb;
3030
static constexpr lldb::user_id_t expected_breakpoint_id = 1;
3131
static constexpr lldb::user_id_t expected_breakpoint_location_id = 0;
3232

33+
int baton_value;
34+
3335
class BreakpointSetCallbackTest : public ::testing::Test {
3436
public:
3537
static void CheckCallbackArgs(void *baton, StoppointCallbackContext *context,
3638
lldb::user_id_t break_id,
3739
lldb::user_id_t break_loc_id,
3840
TargetSP expected_target_sp) {
3941
EXPECT_EQ(context->exe_ctx_ref.GetTargetSP(), expected_target_sp);
40-
EXPECT_EQ(baton, "hello");
42+
EXPECT_EQ(baton, &baton_value);
4143
EXPECT_EQ(break_id, expected_breakpoint_id);
4244
EXPECT_EQ(break_loc_id, expected_breakpoint_location_id);
4345
}
@@ -55,7 +57,6 @@ class BreakpointSetCallbackTest : public ::testing::Test {
5557
};
5658

5759
TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
58-
void *baton = (void *)"hello";
5960
// Set up the debugger, make sure that was done properly.
6061
TargetSP target_sp;
6162
ArchSpec arch("x86_64-apple-macosx-");
@@ -78,7 +79,7 @@ TEST_F(BreakpointSetCallbackTest, TestBreakpointSetCallback) {
7879
CheckCallbackArgs(baton, context, break_id, break_loc_id, target_sp);
7980
return true;
8081
},
81-
baton, true);
82+
(void *)&baton_value, true);
8283
ExecutionContext exe_ctx(target_sp, false);
8384
StoppointCallbackContext context(nullptr, exe_ctx, true);
8485
breakpoint_sp->InvokeCallback(&context, 0);

0 commit comments

Comments
 (0)