1
0
forked from alex-eg/sex

start a global from braces, not a compound literal

A compound literal is no constant in C11, so a global built by a
constructor or a typed literal failed under -pedantic-errors; gcc says
so, clang lets it pass.
This commit is contained in:
2026-10-15 11:20:53 +03:00
parent 6cda0873c6
commit 913af0b463
3 changed files with 27 additions and 6 deletions

View File

@@ -1878,7 +1878,8 @@
core
(if (> (length core) 3)
(append (take core 3)
(walk-operands core (drop core 3) env))
(map bare-braces
(walk-operands core (drop core 3) env)))
core))
env)))
(form (if qualifier
@@ -1888,6 +1889,17 @@
(add-name-type! (second core) (third core)))
(cons form (append (hash-table-ref env :lambda-aux-code) acc))))
;;; A compound literal is not a constant, though cc lets one pass at file
;;; scope unless asked to be pedantic; where it initializes, its braces
;;; alone say the same:
;;;
;;; (var g t (t/a 1)) -> static t g = {.tag = tǂa, .u = {.a = {1}}}
(define (bare-braces form)
(if (vector? form)
(let ((parts (list-split (vector->list form) ':)))
(list->vector (map bare-braces (last parts))))
form))
;;; Utils
(define (non-empty-list? form)
(and (list? form)