[vim/vim] C++ syntax highlighting does the wrong thing with brace initialization in lambda captures (Issue #11639)

49 views
Skip to first unread message

Aaron Jacobs

unread,
Nov 28, 2022, 4:22:32 PM11/28/22
to vim/vim, Subscribed

Steps to reproduce

Input the following code:

auto Foo() {
  return int64_t{0};
}

auto Bar() {
  return [calls = int64_t{0}]() mutable { return ++calls; };
}

The result is syntax highlighting that shows the second int64_t{0} expression as problematic, and the first as fine:

7JAEGdoXYnJ2sdk

Expected behaviour

The int64_t{0} expression is valid in both places, so both should be rendered the same (without the pink highlighting in my screenshot).

Version of Vim

9.0

Environment

OS: Linux
$TERM: screen-256color

Logs and stack traces

No response


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/11639@github.com>

bfrg

unread,
Nov 28, 2022, 5:53:08 PM11/28/22
to vim/vim, Subscribed

You need to add let g:c_no_curly_error = 1 in your vimrc to suppress this type of syntax error. Don't forget to reload the buffer after that.

There are plenty of other variables that you can set. See :h ft-c-syntax.


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/11639/1329857744@github.com>

Aaron Jacobs

unread,
Nov 28, 2022, 9:29:53 PM11/28/22
to vim/vim, Subscribed

Nice, thanks! Do you know why that isn't the default? It seems like the wrong default as of C++14.


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/11639/1329994125@github.com>

bfrg

unread,
Nov 29, 2022, 1:15:30 PM11/29/22
to vim/vim, Subscribed

Note that the defaults are defined in the c syntax file. The file is just also loaded for cpp files since the syntax is very similar. I don't know who wrote the syntax file nor who made those decisions.


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/11639/1331096185@github.com>

Aaron Jacobs

unread,
Nov 29, 2022, 5:57:30 PM11/29/22
to vim/vim, Subscribed

Ack, thanks. Feel free to read this issue as "the defaults are wrong for C++" then, which I think is a legitimate issue. (Great that there's a workaround though, thanks for that.)


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/11639/1331423920@github.com>

Christian Brabandt

unread,
Nov 30, 2022, 2:12:14 AM11/30/22
to vim/vim, Subscribed

C++ is just hard to parse correctly. I guess we have to live with it. Here is a quote from Bram about this

C++ is close to impossible to parse correctly, anything that wasn't an error in the previous version is made to do something meaningful in the next version, it seems. This will continue until any random sequence of characters is meaningful C++ code :-).
I used to know C++ but don't quite understand your example. Is {1,1} a tuple literal?

The syntax file was made to highlight the most obvious errors.
You an disable highlighting curly errors, but then Vim won't highlight unpatched "}". It's up to the user to decide what is preferred.)


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/11639/1331730220@github.com>

Christian Brabandt

unread,
Nov 30, 2022, 2:18:50 AM11/30/22
to vim/vim, Subscribed

Having said that, this is most likely a duplicate of various of the following issues:

#3551 and possibly others: https://github.com/vim/vim/issues?q=is%3Aissue+c_no_curly_error


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/11639/1331735589@github.com>

bfrg

unread,
Mar 26, 2023, 11:31:44 AM3/26/23
to vim/vim, Subscribed

Since it's a duplicate I think it can be closed.


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/11639/1484132275@github.com>

Christian Brabandt

unread,
Mar 27, 2023, 2:15:22 AM3/27/23
to vim/vim, Subscribed

closing then


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/11639/1484556406@github.com>

Christian Brabandt

unread,
Mar 27, 2023, 2:15:22 AM3/27/23
to vim/vim, Subscribed

Closed #11639 as not planned.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/issue/11639/issue_event/8850071622@github.com>

Reply all
Reply to author
Forward
0 new messages