]> git.ipfire.org Git - thirdparty/shadow.git/commit
lib/cast.h: const_cast(): Add macro for dropping 'const'
authorAlejandro Colomar <alx@kernel.org>
Sun, 7 Jan 2024 00:00:45 +0000 (01:00 +0100)
committerIker Pedrosa <ikerpedrosam@gmail.com>
Fri, 26 Jan 2024 08:40:10 +0000 (09:40 +0100)
commite9fc8fc7ef3ed69fcccc4eef0d13f193a3bde7cc
tree21f16dadf188df9d4654e7acff9dd88c59a887af
parent4ef08548ccaa44116d009566942624f611cb4681
lib/cast.h: const_cast(): Add macro for dropping 'const'

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>
lib/Makefile.am
lib/cast.h [new file with mode: 0644]