Skip to content
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

Struct members with a name that starts with a variable type get mis-categorized. #265

Closed
alexr00 opened this issue Jun 27, 2019 · 5 comments · Fixed by #267
Closed

Struct members with a name that starts with a variable type get mis-categorized. #265

alexr00 opened this issue Jun 27, 2019 · 5 comments · Fixed by #267
Labels
🐛 Bug Something isn't working

Comments

@alexr00
Copy link

alexr00 commented Jun 27, 2019

From @LeandreBl here microsoft/vscode#76165
The problem does not occur when the file is tagged as a C++ file, only in C

Steps to Reproduce:

  1. Write any line, in a C tagged file, with the syntax of a structure usage
  2. For example
int main(void)
{
    im_a_struct.im_a_member = 0; /* works fine */
    im_a_struct.integer_member = 0; /* starts with a variable type "int", no color */
    im_a_struct.size_t_holder = 0; /* does not work too */
    im_a_struct.intra_thread = thread(); /* same issue, starts with "int" */
    im_a_struct.long_array = malloc(10000); /* "long" keyword */
}

The im_a_struct.im_a_member line gets additional scopes (variable.other.object.access.c for im_a_struct and variable.other.member.c for im_a_member) but the lines below it just have meta.block.c.

matter123 added a commit that referenced this issue Jun 27, 2019
@jeff-hykin jeff-hykin added Syntax: C For bugs that only occur in C 🐛 Bug Something isn't working labels Jun 27, 2019
@jeff-hykin
Copy link
Owner

jeff-hykin commented Jun 27, 2019

Thanks @matter123

@alexr00 the bounds were messed up so it was messed up for all the keywords, thankfully the one change fixes all of them.

@LeandreBl the initial fix has been push in v1.12.6, the change should show up in a later version of VS Code. If you want the fix right now download the Better Syntax extension and it will automatically be applied

@jeff-hykin
Copy link
Owner

jeff-hykin commented Jun 27, 2019

The bad news is @matter123 I just realized size_t actually can be a member 😓
The following code outputs "10" on gcc/clang

struct A {
    int size_t = 10;
};
int main(int argc, char *argv[])
    {
        A a{10};
        cout << a.size_t << "\n";
        return 0;
    }

I'm not sure if this is in accordance with the language spec, and I'm not sure which types it applies to. Whatever types it does apply to, I'd say initially lets assume its a type unless it's preceded with a member access operator, meaning it would still be marked incorrectly inside of the struct. We'll have to wait till after variable declares/definitions are working before fixing it inside of structs.

@jeff-hykin jeff-hykin reopened this Jun 27, 2019
@jeff-hykin jeff-hykin removed the Syntax: C For bugs that only occur in C label Jun 27, 2019
@matter123
Copy link
Collaborator

The C11 standard in 7.1.3/1.4 (N1570) explicitly says that any symbols with external linkage (rather than static linkage) are reserved. The definition of the header <stddef.h> does not say that size_t has static linkage. 7.19/2. Therefore the use of size_t as anything other than what <stddef.h> defines it as, violates the C standard.

@jeff-hykin
Copy link
Owner

Ah okay excellent. Your knowledge of the standard is impeccable as usual 👍

@matter123
Copy link
Collaborator

C++ has a similar requirement in [extern.names]/3

Each name from the C standard library declared with external linkage is reserved to the implementation for use as a name with extern "C" linkage, both in namespace std and in the global namespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants