[libc-commits] [libc] [libc] Use QUEUE_TYPEOF in STAILQ_LAST (PR #79011)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Mon Jan 22 09:03:07 PST 2024


https://github.com/petrhosek created https://github.com/llvm/llvm-project/pull/79011

This is to ensure this macro is compatible with both C and C++.

>From 070aac8a9f8e0e8a85bb698dc1309918bae7d66d Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Mon, 22 Jan 2024 17:01:17 +0000
Subject: [PATCH] [libc] Use QUEUE_TYPEOF in STAILQ_LAST

This is to ensure this macro is compatible with both C and C++.
---
 libc/include/llvm-libc-macros/sys-queue-macros.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libc/include/llvm-libc-macros/sys-queue-macros.h b/libc/include/llvm-libc-macros/sys-queue-macros.h
index f41e7363e418bf4..59e6a9a392c9781 100644
--- a/libc/include/llvm-libc-macros/sys-queue-macros.h
+++ b/libc/include/llvm-libc-macros/sys-queue-macros.h
@@ -160,7 +160,9 @@
 #define STAILQ_EMPTY(head) ((head)->first == NULL)
 #define STAILQ_FIRST(head) ((head)->first)
 #define STAILQ_LAST(head, type, field)                                         \
-  (STAILQ_EMPTY(head) ? NULL : __containerof((head)->last, type, field.next))
+  (STAILQ_EMPTY(head)                                                          \
+       ? NULL                                                                  \
+       : __containerof((head)->last, QUEUE_TYPEOF(type), field.next))
 #define STAILQ_NEXT(elem, field) ((elem)->field.next)
 
 #define STAILQ_FOREACH(var, head, field)                                       \



More information about the libc-commits mailing list