Skip to content

Commit 82b4e51

Browse files
[libc] fix -Wcast-qual in containerof macro
Fixes the diagnostic observed with gcc-14: llvm-project/libc/include/llvm-libc-macros/containerof-macro.h:17:13: error: cast from type ‘const char*’ to type ‘void*’ casts away qualifiers [-Werror=cast-qual] 17 | (type *)(void *)((const char *)__ptr - offsetof(type, member)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We're trying to turn on more warnings for the tests in llvm#124036, so enable -Wcast-qual for GCC while we're at it.
1 parent d398c0c commit 82b4e51

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

libc/cmake/modules/LLVMLibCTestRules.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ function(_get_common_test_compile_options output_var c_test flags)
4646
if(NOT c_test)
4747
list(APPEND compile_options "-fext-numeric-literals")
4848
endif()
49+
list(APPEND compile_options "-Wcast-qual")
4950
else()
5051
list(APPEND compile_options "-Wno-c99-extensions")
5152
list(APPEND compile_options "-Wno-gnu-imaginary-constant")

libc/include/llvm-libc-macros/containerof-macro.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
#define __containerof(ptr, type, member) \
1515
({ \
16-
const __typeof(((type *)0)->member) *__ptr = (ptr); \
17-
(type *)(void *)((const char *)__ptr - offsetof(type, member)); \
16+
typeof(((type *)0)->member) *__ptr = (ptr); \
17+
(type *)(void *)((char *)__ptr - offsetof(type, member)); \
1818
})
1919

2020
#endif // LLVM_LIBC_MACROS_CONTAINEROF_MACRO_H

0 commit comments

Comments
 (0)