mirror of
https://github.com/shadow-maint/shadow.git
synced 2024-11-27 12:04:17 +08:00
e9fc8fc7ef
Uses of this macro indicate a code smell, but in some cases, libc functions require breaking const correctness. Use this macro to wrap casts in such cases, so that we limit the danger of the cast. It only permits discarding const. Discarding any other qualifiers, or doing other type changes should result in a compile-time error. Link: <https://software.codidact.com/posts/286575/287345#answer-287345> Signed-off-by: Alejandro Colomar <alx@kernel.org>
22 lines
568 B
C
22 lines
568 B
C
// SPDX-FileCopyrightText: 2022-2024, Alejandro Colomar <alx@kernel.org>
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
|
#ifndef SHADOW_INCLUDE_LIB_CAST_H_
|
|
#define SHADOW_INCLUDE_LIB_CAST_H_
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include "must_be.h"
|
|
|
|
|
|
#define const_cast(T, p) \
|
|
({ \
|
|
static_assert(is_same_type(typeof(&*(p)), const T), ""); \
|
|
(T) (p); \
|
|
})
|
|
|
|
|
|
#endif // include guard
|