take a name after a qualified type as the bound

[int const N] read N as the type a trailing const was waiting for, and
wrote int const N b[]; a qualifier waits for a name only when no type
came before it.
This commit is contained in:
2026-10-15 14:48:25 +03:00
parent dd1718dffb
commit 6ced17c20e
2 changed files with 19 additions and 7 deletions

View File

@@ -775,7 +775,14 @@ whitespace aside, THEN?"
(test-assert "nor is an aggregate tag"
(emits? "(struct t ((z int))) (struct s ((a [struct t])))" "struct t a[]"))
(test-assert "nor one behind a pointer"
(emits? "(struct t ((z int))) (struct s ((a [* struct t])))" "struct t* a[]")))
(emits? "(struct t ((z int))) (struct s ((a [* struct t])))" "struct t* a[]"))
;; a qualifier waits for a type name only when none came before it
(test-assert "a name after a qualified type is a bound"
(emits? (in-fn "(var b [int const N])") "int const b[N]"))
(test-assert "after a qualified name too"
(emits? (in-fn "(var b [mytype const N])") "mytype const b[N]"))
(test-assert "but a qualifier alone still waits for the type"
(emits? "(typedef mytype int) (struct s ((a [const mytype])))" "const mytype a[]")))
;; `sizeof' takes a type or an expression, and `(* x)' is either.
;; What is in scope says which: a name C alone knows is a type