Skip to content

C++ syntax highlighting falls apart after specific struct syntax #652

@alexr00

Description

@alexr00

Checklist

  • This problem exists even with the setting "C_Cpp.enhancedColorization": "Disabled"

If Disabling that^ makes the problem go away, then follow this to make an issue on the C++ extension:
https://github.com/microsoft/vscode-cpptools/issues/new/choose

The code with a problem is:

struct foo
{
	void (*bar1)() noexcept;
	void (*bar2)() noexcept;
	void (*bar3)() noexcept;
};

void baz()
{
	static_assert(false, "some string");
	int x = 0;
}

It looks like:

In latest insiders with the default theme
image

More issues are apparent depending on the theme being used
image

It should look like:

Here's the snippet again with some of the issues annotated. It appears as though the parser gets confused on the first function pointer and essentially thinks all the things after it are parameters in the function pointer type.

struct foo
{
    void (*bar1)() noexcept;        // noexcept is entity.name.type.parameter, should be storage.modifier.special.functional.post-parameters.noexcept.cpp
    void (*bar2)() noexcept;        // bar2 is variable.parameter.pointer.function, should be variable.other.pointer.function.cpp
    void (*bar3)() noexcept;
};                                  // } is meta.parameter.cpp, should be punctuationsection.block.end.bracket.curly.struct.cpp

void baz()                          // baz is entity.name.type.parameter.cpp, should be entity.name.function.definition.cpp
{
    static_assert(false, "string");
    int x = 0;                      // line is string.quoted.double.cpp
}

Originally from @akbyrd in microsoft/vscode#202365

Metadata

Metadata

Assignees

No one assigned

    Labels

    High PriorityCommon or breaks highlighting of more than just itself

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions