Skip to content

Intellisense marks unnamed struct/union members as errors, but gcc does not #3063

@nurbles

Description

@nurbles

Type: LanguageService
I am not sure if I am asking for a feature or reporting a bug. I believe it is about something that intellisense is doing wrong, but since it could have been intentionally left out (because a developer didn't know gcc supported this feature, perhaps) I may be asking for a new feature. Or, most likely, I just cannot discover the correct combination of settings to get intellisense to work as I need.

I am using (I update EVERY day before starting to use vscode):

Ubuntu 18.04.1.LTS
VSCode Version: 1.31.0-insider
Commit: e9bb33f
Date: 2019-01-21T06:16:03.813Z
Electron: 3.0.13
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Linux x64 4.15.0-43-generic
C/C++ Intellisense extension version: 0.21.0-insiders4

The issue I am reporting (or feature I am requesting)
I started using the -fms-extensions switch on the gcc command line to allow unnamed struct/union members, but intellisense is flagging all references to those members as errors. (I'm building on an embedded box, so vscode doesn't get any compiler output [which has zero errors or warnings[).

I had learned to like vscode/intellisense's ability to let me know about errors BEFORE I sent the source to the embedded box to be built, but now my code shows too many errors that actually are NOT errors for me to find all the REAL mistakes I make! Hopefully intellisense can stop flagging these valid statements as errors, at least when told to allow them (but how is that done?)

I am using this for c_cpp_properties.json ((updated to a corrected c_cpp_properties.json file):

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/lib/gcc/x86_64-linux-gnu/7/include",
                "/usr/local/include",
                "/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed",
                "/usr/include/x86_64-linux-gnu",
                "/usr/include"
                           ],
            "defines": [ "RM23S", "VerNum=0x00010000" ],
            "compilerPath": "/usr/bin/gcc -fms-extension",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

If I have this source file:

typedef struct UnnamedTest_s
{
   int   a;
   union Unnamed_u
   {
      unsigned char Byte;
      unsigned short Word;
      unsigned long Dword;
   };
   int   b;
   unsigned char  uc;
   unsigned short us;
   unsigned long  ul;
} UnnamedTest;

int main( int argc, char **argv )
{
   UnnamedTest test;
   
   test.uc = test.Byte;
   test.us = test.Word;
   test.ul = test.Dword;
   return 0;
}

The Byte, Word, and Dword members have the red squiggly underline that indicates and error. However, the -fms-extensions switch means those are not errors.

Expected behavior
I do not expect intellisense to mark valid code as an error.

Reference
The gcc documentation says that unnamed fields are allowed by C11 and supported by gcc:
gcc Unnamed Fields

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature RequestLanguage ServiceVisual StudioInherited from Visual StudiofixedCheck the Milestone for the release in which the fix is or will be available.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions