diff mbox series

[2/2] make implicit type conversion explicit

Message ID 20210813012511.65397-3-duke@naive.systems (mailing list archive)
State New
Headers show
Series fixes for using sparse as a C++ library | expand

Commit Message

Ke Du Aug. 13, 2021, 1:25 a.m. UTC
Make implicit type converison from void* to other types explicit so
ptrlist.h and token.h can be included as C++ library. Without this
change, when including these in C++, clang complains that it cannot
initialize return object of a more specific type with an lvalue of type
void*.

Signed-off-by: Ke Du <duke@naive.systems>
Reviewed-by: Xiao Jia <xjia@naive.systems>
---
 ptrlist.h | 2 +-
 token.h   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/ptrlist.h b/ptrlist.h
index 67c7a208..9fd20f84 100644
--- a/ptrlist.h
+++ b/ptrlist.h
@@ -303,7 +303,7 @@  extern void split_ptr_list_head(struct ptr_list *);
 
 static inline void update_tag(void *p, unsigned long tag)
 {
-	unsigned long *ptr = p;
+	unsigned long *ptr = (unsigned long *)p;
 	*ptr = tag | (~3UL & *ptr);
 }
 
diff --git a/token.h b/token.h
index 804cc6f8..7a97a478 100644
--- a/token.h
+++ b/token.h
@@ -204,7 +204,7 @@  struct token {
 static inline struct token *containing_token(struct token **p)
 {
 	void *addr = (char *)p - ((char *)&((struct token *)0)->next - (char *)0);
-	return addr;
+	return (struct token *)addr;
 }
 
 #define token_type(x) ((x)->pos.type)