-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
(c) Declaration of struct variable triggers class title mode #2736
Comments
I think the struct class-like rule could be enhanced to ONLY match |
Yes, that was my initial thought as well. However, since C and C++ are currently the same definition we need to do some extra work since the following are all also valid: struct C;
struct C : A { …
struct C final : A { …
struct C : A<B<C>> { …
template <> struct C<void> { …
struct [[using CC: opt(1), debug]] [[foo([[]])]] C { …
struct N::N1::C { …
template struct N::C<char*>::D<void> { …
struct alignas(8) C { …
struct __declspec(dllexport) C { …
struct __attribute__((__packed__)) C { … And of course any and all parts in the above may be hidden behind macros. Damn I hate C++ syntax … |
As a best-effort heuristic, we might consider something like this (not sure how easy even that is to implement, since it backtracks):
|
Will it greatly simplify things if the grammars were split? I presume that the C one would be much simpler but would it reduce the complexity of the C++ problem? |
It would for C, but since I’m also interested in good C++ support that doesn’t help me personally. ;-) (Since virtually all relevant C code is also legal C++, the split won’t simplify the C++ grammar.) That said, yes, I think now’s the time to split the two grammars (#2146). I’m happy to work on this. |
If seems right now we're at the same fidelity as GitHub which seems to highlight the second term after |
@joshgoebel it is notable that in C the word following C++: struct tag *foo = malloc(sizeof (struct tag)); Strangely enough, that is not used for C on Github: struct tag *foo = malloc(sizeof (struct tag)); |
Yes, the C rule will be much easier to get right when we split the grammars. I'm not opposed to looking at what it might take to get it perfect for C++ also, but I'm worried it'll be too complex. |
This list you provided in #2736 (comment) If we split it up between C and C++ what would those two sep lists look like? |
Cstruct C;
typedef struct { … } C;
struct __declspec(dllexport) C { …
struct __attribute__((packed, aligned(4))) C { …
typedef struct C { … } __attribute__((packed)) C; Furthermore, @ztane made the point that C structs can have nothing between the C++All of the above, plus struct C : A { …
struct C final : A { …
struct C : private A { …
struct C : A<B<C>> { …
template <typename T> struct C { …
template <template <typename> class T> struct C { …
template <> struct C<void> { …
struct [[using CC: opt(1), debug]] [[foo([[]])]] C { …
struct N::N1::C { …
template struct N::C<char*>::D<void> { …
struct alignas(8) C { … Furthermore, C++ also allows |
Describe the issue
When declaring a variable of type
struct foobar
, this triggers the rule for a struct/class title, which leads to the whole declaration being highlighted as a title. See https://meta.stackexchange.com/a/354753/1968.Which language seems to have the issue?
c
/cpp
Are you using
highlight
orhighlightAuto
?highlight
Sample Code to Reproduce
This is rendered as
Expected behavior
Should render as
Additional context
Without the initial
struct
the highlighter doesn’t trigger class/title mode. It still doesn’t correctly render thestruct
keywords in the rest of the initialisation but that’s already addressed (incidentally) by #2728.The text was updated successfully, but these errors were encountered: