[vim/vim] runtime(c): correct struct initializers get highlighted as errors (Issue #18709)

9 views
Skip to first unread message

dzwdz

unread,
Nov 9, 2025, 4:46:19 PM11/9/25
to vim/vim, Subscribed
dzwdz created an issue (vim/vim#18709)

Steps to reproduce

  1. :syntax on
  2. open up e.g. musl's src/linux/settimeofday.c, or paste it in (then you'll need set syntax=c)
  3. the braces in the struct timespec get highlighted as errors
image.png (view on web)

Expected behaviour

The braces shouldn't get highlighted. I can work around it with let g:no_curly_error = 1, but ideally I wouldn't need that.

Version of Vim

9.1, Included patches: 1-948, 950, 1230-1242, 1244

Environment

tested with vim -u NONE on Debian 13.1, the exact package version is 2:9.1.1230-2

Logs and stack traces


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/18709@github.com>

dkearns

unread,
Nov 9, 2025, 11:15:38 PM11/9/25
to vim/vim, Subscribed
dkearns left a comment (vim/vim#18709)

I'm surprised this doesn't hit people all the time. Maybe everyone disables the error highlighting?

Something like the following might be sufficient but I have given it very little thought:

diff --git a/runtime/syntax/c.vim b/runtime/syntax/c.vim
index 68b6778c7..3943dbdc1 100644
--- a/runtime/syntax/c.vim
+++ b/runtime/syntax/c.vim
@@ -173,7 +173,7 @@ elseif exists("c_no_bracket_error")
     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
     syn region cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
     syn match  cParenError     display ")"
-    syn match  cErrInParen     display contained "[{}]\|<%\|%>"
+    syn match  cErrInParen     display contained "\%()\s*\)\@<!{\|[}]\|<%\|%>"
   endif
 else
   if s:in_cpp_family && !exists("cpp_no_cpp11")
@@ -188,7 +188,7 @@ else
     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
     syn region cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
     syn match  cParenError     display "[\])]"
-    syn match  cErrInParen     display contained "[\]{}]\|<%\|%>"
+    syn match  cErrInParen     display contained "\%()\s*\)\@<!{\|[\]}]\|<%\|%>"
     syn region cBracket        transparent start='\[\|<::\@!' end=']\|:>' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cErrInParen,cCppParen,cCppBracket,@cStringGroup,@Spell
   endif
   " cCppBracket: same as cParen but ends at end-of-line; used in cDefine


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/18709/3509321550@github.com>

bogdan-barbu

unread,
Mar 5, 2026, 1:55:28 PMMar 5
to vim/vim, Subscribed
bogdan-barbu left a comment (vim/vim#18709)

Since my bug report was marked as a duplicate as this, I might as well add some relevant info here. The issue seems to be with aggregate type literals (i.e., literals of array/struct/union types) enclosed in either square brackets or parentheses. But you can't rely on the braces being preceded by a parentheses group, see the last example:

int a[(struct foo){ }.bar];
static_assert(sizeof (int []){ 1, 2, 3 } == 3 * sizeof (int));
for (struct foo i = { };;) ;


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/18709/4007015699@github.com>

Boobies

unread,
Aug 2, 2026, 11:37:26 PM (17 hours ago) Aug 2
to vim/vim, Subscribed
Boobies left a comment (vim/vim#18709)

Is anyone still checking this thread? Btw, I am @bogdan-barbu but made the PR on this account because I lost access to the email associated with that other account.


Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issues/18709/5162028468@github.com>

Reply all
Reply to author
Forward
0 new messages