-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Syntax causes tokenization to break for remainder of file #488
Comments
Does this code use macros? There's probably a more graceful way the syntax can handle this, but if the code isn't using utilizing the preprocessor I'd be very surprised if that code was valid. |
The code does not use macros or the preprocessor in any way and is perfectly valid in all versions of c++ ever; here is a full example that compiles: struct Base {
Base(const char *s_);
const char *s;
};
struct Test : public Base {
Test();
};
Base::Base(const char *s_) : s(s_) {}
Test::Test() : Base ("{}") {
// Broken syntax highlight
} You can place it on a c++ file and compile with any compiler. Edit: live example. |
@jeff-hykin constructors are allowed to call other constructors or the base constructor in the initializer list. This is no different than
Though both highlight correctly for me (if you ignore bracket highlighter getting confused) |
@matter123 It will break highlight if you add a space between |
@marzojr It seems that this may have been fixed sometime between the most recently published version and the version that vscode is using. You can manually install the "Better C++ Syntax" extension, to fix for now. I finally, somewhat, have some time I can put into looking into #460, so hopefully, at some point, the version vscode is using should be able to be updated again. |
@matter123 I tried the extension you mentioned, and it does make the problem much better -- but it is still there. Note that the curly braces in your screenshot are all highlighted as brackets, not as characters inside a character literal. Also, the closing parenthesis of the initializer, as well as the curly braces of the constructor, are incorrectly highlighted. Exploring a bit, most of the syntax highlighting is correct with that extension, but curly braces, square brackets, and parenthesis, are all incorrectly highlighted for the remainder of the file -- they highlight as brackets while inside strings, and are not highlighted outside of strings. Interestingly, changing from |
Are your brackets colored via your color theme or via an extension like "Bracket Pair Colorizer 2"? If you use |
Hm, nice catch; the incorrect bracket highlighting is coming from "Bracker Pair Colorizer 2", and with it disabled, it seems that "Better C++ Syntax" fixes this issue. |
Closing this as this is fixed in a released version. |
Thanks for taking care of this. And well, I guess consider me surprised, I didn't account for the case of an external initializer list. I guess I'm a bit too used to inline constructors. |
Checklist
"C_Cpp.enhancedColorization": "Disabled"
The code with a problem is:
It looks like:
It should look like:
It looks like things start to go wrong on the first curly brace, which ends up with these scopes:
The text was updated successfully, but these errors were encountered: