[Lldb-commits] [lldb] b1d75fe - [lldb][test] Fix cast dropping const warnin in TestBreakpointSetCallback.cpp
David Spickett via lldb-commits
lldb-commits at lists.llvm.org
Mon Aug 19 08:18:11 PDT 2024
Author: David Spickett
Date: 2024-08-19T15:16:04Z
New Revision: b1d75fe48c940ba677614db3d891fbebcb8a41a2
URL: https://github.com/llvm/llvm-project/commit/b1d75fe48c940ba677614db3d891fbebcb8a41a2
DIFF: https://github.com/llvm/llvm-project/commit/b1d75fe48c940ba677614db3d891fbebcb8a41a2.diff
LOG: [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.
Added:
Modified:
lldb/unittests/Callback/TestBreakpointSetCallback.cpp
Removed:
################################################################################
diff --git a/lldb/unittests/Callback/TestBreakpointSetCallback.cpp b/lldb/unittests/Callback/TestBreakpointSetCallback.cpp
index 2a7070f9349c02..3dba4a9eb719e3 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 @@ class BreakpointSetCallbackTest : public ::testing::Test {
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 @@ class BreakpointSetCallbackTest : public ::testing::Test {
};
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);
More information about the lldb-commits
mailing list