]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/cast.h: const_cast(): Reimplement with _Generic(3)
authorAlejandro Colomar <alx@kernel.org>
Wed, 15 May 2024 11:19:43 +0000 (13:19 +0200)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Tue, 4 Jun 2024 07:10:23 +0000 (09:10 +0200)
This makes it much simpler and portable.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/cast.h

index 9229528d0a3952b8db901065cd53a1c5cc4a3f48..5cbbcf6dd48d96b11b1a8a2d312c186a887314fd 100644 (file)
@@ -8,14 +8,8 @@
 
 #include <config.h>
 
-#include "must_be.h"
 
-
-#define const_cast(T, p)                                                      \
-({                                                                            \
-       static_assert(is_same_type(typeof(&*(p)), const T), "");              \
-       (T) (p);                                                              \
-})
+#define const_cast(T, p)  _Generic(p, const T:  (T) (p))
 
 
 #endif  // include guard