compiler: use C23 auto when available

One annoying thing is C23 still defines auto as a storage class despite
it now being used for type inference. As a consequence we must write
"auto const" instead of the more natural "const auto".

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui
2023-12-17 08:55:23 +00:00
parent 1b97f18e5f
commit e92745671b
5 changed files with 27 additions and 25 deletions

View File

@@ -176,8 +176,8 @@ static xcb_render_picture_t process_mask(struct _xrender_data *xd, struct xrende
*allocated = false;
return inner->pict;
}
const auto tmpw = to_u16_checked(inner->width);
const auto tmph = to_u16_checked(inner->height);
auto const tmpw = to_u16_checked(inner->width);
auto const tmph = to_u16_checked(inner->height);
*allocated = true;
x_clear_picture_clip_region(xd->base.c, inner->pict);
auto ret = x_create_picture_with_visual(
@@ -226,13 +226,13 @@ compose_impl(struct _xrender_data *xd, struct xrender_image *xrimg, coord_t dst,
region_t reg;
bool has_alpha = inner->has_alpha || img->opacity != 1;
const auto tmpw = to_u16_checked(inner->width);
const auto tmph = to_u16_checked(inner->height);
const auto tmpew = to_u16_checked(img->ewidth);
const auto tmpeh = to_u16_checked(img->eheight);
auto const tmpw = to_u16_checked(inner->width);
auto const tmph = to_u16_checked(inner->height);
auto const tmpew = to_u16_checked(img->ewidth);
auto const tmpeh = to_u16_checked(img->eheight);
// Remember: the mask has a 1-pixel border
const auto mask_dst_x = to_i16_checked(dst.x - mask_dst.x + 1);
const auto mask_dst_y = to_i16_checked(dst.y - mask_dst.y + 1);
auto const mask_dst_x = to_i16_checked(dst.x - mask_dst.x + 1);
auto const mask_dst_y = to_i16_checked(dst.y - mask_dst.y + 1);
const xcb_render_color_t dim_color = {
.red = 0, .green = 0, .blue = 0, .alpha = (uint16_t)(0xffff * img->dim)};
@@ -395,8 +395,8 @@ static bool blur(backend_t *backend_data, double opacity, void *ctx_, void *mask
resize_region(&reg_op, bctx->resize_width, bctx->resize_height);
const pixman_box32_t *extent_resized = pixman_region32_extents(&reg_op_resized);
const auto height_resized = to_u16_checked(extent_resized->y2 - extent_resized->y1);
const auto width_resized = to_u16_checked(extent_resized->x2 - extent_resized->x1);
auto const height_resized = to_u16_checked(extent_resized->y2 - extent_resized->y1);
auto const width_resized = to_u16_checked(extent_resized->x2 - extent_resized->x1);
static const char *filter0 = "Nearest"; // The "null" filter
static const char *filter = "convolution";

View File

@@ -7,7 +7,9 @@
#endif
// clang-format off
#if __STDC_VERSION__ <= 201710L
#define auto __auto_type
#endif
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define likely_if(x) if (likely(x))

View File

@@ -265,7 +265,7 @@ void schedule_render(session_t *ps, bool triggered_by_vblank) {
goto schedule;
}
const auto deadline = ps->last_msc_instant + (unsigned long)divisor * frame_time;
auto const deadline = ps->last_msc_instant + (unsigned long)divisor * frame_time;
unsigned int available = 0;
if (deadline > now_us) {
available = (unsigned int)(deadline - now_us);
@@ -1158,7 +1158,7 @@ static int register_cm(session_t *ps) {
// Set WM_CLIENT_MACHINE. As per EWMH, because we set _NET_WM_PID, we must also
// set WM_CLIENT_MACHINE.
{
const auto hostname_max = (unsigned long)sysconf(_SC_HOST_NAME_MAX);
auto const hostname_max = (unsigned long)sysconf(_SC_HOST_NAME_MAX);
char *hostname = malloc(hostname_max);
if (gethostname(hostname, hostname_max) == 0) {

View File

@@ -474,10 +474,10 @@ void paint_one(session_t *ps, struct managed_win *w, const region_t *reg_paint)
} else {
// Painting parameters
const margin_t extents = win_calc_frame_extents(w);
const auto t = extents.top;
const auto l = extents.left;
const auto b = extents.bottom;
const auto r = extents.right;
auto const t = extents.top;
auto const l = extents.left;
auto const b = extents.bottom;
auto const r = extents.right;
#define COMP_BDR(cx, cy, cwid, chei) \
paint_region(ps, w, (cx), (cy), (cwid), (chei), w->frame_opacity * w->opacity, \
@@ -888,8 +888,8 @@ win_blur_background(session_t *ps, struct managed_win *w, xcb_render_picture_t t
const region_t *reg_paint) {
const int16_t x = w->g.x;
const int16_t y = w->g.y;
const auto wid = to_u16_checked(w->widthb);
const auto hei = to_u16_checked(w->heightb);
auto const wid = to_u16_checked(w->widthb);
auto const hei = to_u16_checked(w->heightb);
const int cr = w ? w->corner_radius : 0;
double factor_center = 1.0;
@@ -1174,8 +1174,8 @@ void paint_all(session_t *ps, struct managed_win *t) {
if (w->corner_radius > 0 && ps->o.backend == BKEND_GLX) {
const int16_t x = w->g.x;
const int16_t y = w->g.y;
const auto wid = to_u16_checked(w->widthb);
const auto hei = to_u16_checked(w->heightb);
auto const wid = to_u16_checked(w->widthb);
auto const hei = to_u16_checked(w->heightb);
glx_bind_texture(ps, &w->glx_texture_bg, x, y, wid, hei);
}
#endif
@@ -1195,8 +1195,8 @@ void paint_all(session_t *ps, struct managed_win *t) {
// Rounded corners for XRender is implemented inside render()
// Round window corners
if (w->corner_radius > 0 && ps->o.backend == BKEND_GLX) {
const auto wid = to_u16_checked(w->widthb);
const auto hei = to_u16_checked(w->heightb);
auto const wid = to_u16_checked(w->widthb);
auto const hei = to_u16_checked(w->heightb);
glx_round_corners_dst(ps, w, w->glx_texture_bg, w->g.x,
w->g.y, wid, hei,
(float)ps->psglx->z - 0.5F,

View File

@@ -2758,7 +2758,7 @@ void win_clear_flags(struct managed_win *w, uint64_t flags) {
}
void win_set_properties_stale(struct managed_win *w, const xcb_atom_t *props, int nprops) {
const auto bits_per_element = sizeof(*w->stale_props) * 8;
auto const bits_per_element = sizeof(*w->stale_props) * 8;
size_t new_capacity = w->stale_props_capacity;
// Calculate the new capacity of the properties array
@@ -2793,12 +2793,12 @@ static void win_clear_all_properties_stale(struct managed_win *w) {
}
static bool win_fetch_and_unset_property_stale(struct managed_win *w, xcb_atom_t prop) {
const auto bits_per_element = sizeof(*w->stale_props) * 8;
auto const bits_per_element = sizeof(*w->stale_props) * 8;
if (prop >= w->stale_props_capacity * bits_per_element) {
return false;
}
const auto mask = 1UL << (prop % bits_per_element);
auto const mask = 1UL << (prop % bits_per_element);
bool ret = w->stale_props[prop / bits_per_element] & mask;
w->stale_props[prop / bits_per_element] &= ~mask;
return ret;