[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-sparse
Subject:    [PATCH 2/2] make implicit type conversion explicit
From:       Ke Du <duke () naive ! systems>
Date:       2021-08-13 1:25:11
Message-ID: 20210813012511.65397-3-duke () naive ! systems
[Download RAW message or body]

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 --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)
-- 
2.31.1

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic