better-cpp-syntax icon indicating copy to clipboard operation
better-cpp-syntax copied to clipboard

Switch case highlighting issue with C cast style

Open jaudiger opened this issue 5 years ago • 6 comments

  • [x] This problem exists even with the setting "C_Cpp.enhancedColorization": "Disabled"
  • [x] This bug exists for C
  • [ ] This bug exists for C++
  • [ ] This bug exists for Objective-C
  • [ ] This bug exists for Objective-C++

The code with a problem is:

int my_function()
{
    // Stub
    return 0;
}

// Main function
int main(int argc, char *argv[])
{
    int a;

    switch (a)
    {
    case 0:
        (void)my_function();
        break;

    default:
        break;
    }

    return 0;
}

It looks like:

image

It should look like:

Adding a space after (void) fixed the issue. image

jaudiger avatar Oct 22 '19 13:10 jaudiger

Hmm I'm unable to reproduce this behavior (it is yellow for me in both cases), do you have the latest version of the extension installed?

Also if you don't mind me asking, what does casting to void do?

jeff-hykin avatar Oct 22 '19 14:10 jeff-hykin

Really strange, this behaviour have been found internally in our company. I was able to reproduce the bug, that's why I opened this issue.

Well, I'm only using the C/C++ extension (version 0.26.0) and VSCode (version 1.39.2).

Putting the (void) means here we make explicit the discarded value returned by the function. It just serves as a marker to inform that the function returns a value, but this value is discarded.

Edit: Hum. Don't have the same behaviour this time. Only the keyword default is bad highlighted.

image

image

jaudiger avatar Oct 22 '19 14:10 jaudiger

It could be the C++ extension so you might try disabling it, although it is strange that it would affect default

jeff-hykin avatar Oct 22 '19 14:10 jeff-hykin

It seems the problem is here without the C/C++ extension enabled. Can you confirm it ?

jaudiger avatar Oct 22 '19 14:10 jaudiger

@jeff-hykin afaik enhanced colorization will never remove highlighting, it can cause bad highlighting, but none of the scopes it maps to should be colored the same as text.

matter123 avatar Oct 22 '19 15:10 matter123

Ah I found the problem. This doesn't produce for me in C++, however it does in C.

jeff-hykin avatar Oct 22 '19 17:10 jeff-hykin