git: 28cecfe27964 - main - libc: Restrict ATOMIC_VAR_INIT for C23 conformance

From: Warner Losh <imp_at_FreeBSD.org>
Date: Sat, 20 Jun 2026 00:24:51 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=28cecfe27964fdb67497800f5dcd5d3e1033727f

commit 28cecfe27964fdb67497800f5dcd5d3e1033727f
Author:     Faraz Vahedi <kfv@kfv.io>
AuthorDate: 2026-05-01 14:34:44 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2026-06-20 00:23:28 +0000

    libc: Restrict ATOMIC_VAR_INIT for C23 conformance
    
    Omit `ATOMIC_VAR_INIT` when targeting C23, where it has been removed.
    Retain it for earlier C standards and for C++ (as it still remains in
    C++23, albeit marked as deprecated since C17 and C++20.)
    
    Also separate `atomic_init` definitions from `ATOMIC_VAR_INIT` to
    avoid coupling with a deprecated initialisation mechanism.
    
    No functional change intended for `atomic_init`; this is purely a
    conformance and cleanup adjustment.
    
    Signed-off-by: Faraz Vahedi <kfv@kfv.io>
    Reviewed by: imp
    Pull Request: https://github.com/freebsd/freebsd-src/pull/2185
---
 sys/sys/stdatomic.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/sys/sys/stdatomic.h b/sys/sys/stdatomic.h
index c3f9b217519c..2d565ce991be 100644
--- a/sys/sys/stdatomic.h
+++ b/sys/sys/stdatomic.h
@@ -86,11 +86,17 @@
  * 7.17.2 Initialization.
  */
 
+#if __ISO_C_VISIBLE < 2023 || defined(__cplusplus)
 #if defined(__CLANG_ATOMICS)
 #define	ATOMIC_VAR_INIT(value)		(value)
-#define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
 #else
 #define	ATOMIC_VAR_INIT(value)		{ .__val = (value) }
+#endif
+#endif
+
+#if defined(__CLANG_ATOMICS)
+#define	atomic_init(obj, value)		__c11_atomic_init(obj, value)
+#else
 #define	atomic_init(obj, value)		((void)((obj)->__val = (value)))
 #endif