Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/atoi/a2i.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "atoi/strtoi/strtoi.h"
#include "atoi/strtoi/strtou_noneg.h"
#include "cast.h"
#include "typetraits.h"


Expand All @@ -35,7 +36,7 @@
unsigned int: strtou_noneg, \
unsigned long: strtou_noneg, \
unsigned long long: strtou_noneg \
)(s, (char **) endp_, base, min_, max_, &status); \
)(s, const_cast(char **, endp_), base, min_, max_, &status); \
\
if (status != 0) \
errno = status; \
Expand Down
2 changes: 1 addition & 1 deletion lib/cast.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "config.h"


#define const_cast(T, p) _Generic(p, const T: (T) (p))
#define const_cast(T, p) _Generic(p, const T: (T) (p), default: (p))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A down-side of this change is that if T is ever already const-qualified, this code will fail to build (on at least Clang), as const const ... is not a valid type qualifier. The original _Generic() macros handled this by matching const with a pass-thru, and only adding const when it was missing.

@alejandro-colomar alejandro-colomar Feb 26, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kees

$ git log --pretty=reference lib/cast.h
eb71706b (*/: Fix including <config.h> as system header, 2025-07-15)
69f74dbf (lib/cast.h: const_cast(): Reimplement with _Generic(3), 2024-05-15)
e9fc8fc7 (lib/cast.h: const_cast(): Add macro for dropping 'const', 2024-01-07)

By "the original _Generic() macros" you mean this, right?

$ git show 69f74dbf:lib/cast.h | grepc -h const_cast
#define const_cast(T, p)  _Generic(p, const T:  (T) (p))

69f74db (2024-06-04; "lib/cast.h: const_cast(): Reimplement with _Generic(3)")

I think that would also fail for const char *, as it would expand const T as const const char *, right?



#endif // include guard
18 changes: 5 additions & 13 deletions lib/string/strcmp/strcaseprefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,14 @@

#include "attr.h"
#include "cast.h"
#include "typetraits.h"


// string case-insensitive prefix
// strcaseprefix - string case-insensitive prefix
#define strcaseprefix(s, prefix) \
({ \
const char *p_; \
\
p_ = strcaseprefix_(s, prefix); \
\
_Generic(s, \
const char *: p_, \
const void *: p_, \
char *: const_cast(char *, p_), \
void *: const_cast(char *, p_) \
); \
})
( \
const_cast(QChar_of(s) *, strcaseprefix_(s, prefix)) \
)


ATTR_STRING(1) ATTR_STRING(2)
Expand Down
18 changes: 5 additions & 13 deletions lib/string/strcmp/strprefix.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,14 @@

#include "attr.h"
#include "cast.h"
#include "typetraits.h"


// string prefix
// strprefix - string prefix
#define strprefix(s, prefix) \
({ \
const char *p_; \
\
p_ = strprefix_(s, prefix); \
\
_Generic(s, \
const char *: p_, \
const void *: p_, \
char *: const_cast(char *, p_), \
void *: const_cast(char *, p_) \
); \
})
( \
const_cast(QChar_of(s) *, strprefix_(s, prefix)) \
)


ATTR_STRING(1)
Expand Down
Loading