Skip to content

C: False positive errors for a static function when it has a nested struct parameter #8751

@mfederczuk

Description

@mfederczuk

Bug type: Language Service

Describe the bug

  • OS and Version: Ubuntu 21.10

  • VS Code Version: 1.63.2

  • C/C++ Extension Version: 1.7.1 & 1.8.3

  • Other extensions you installed (and if the issue persists after disabling them): Still persists after disabling all other extensions

  • A clear and concise description of what the bug is:

    When a function declaration OR a separate function declaration + its definition is marked as static and it has any parameter whose type is a struct that is nested inside another struct or union (regardless if it is a value or pointer parameter), then the function is marked with the error declaration is incompatible with "void func_name(struct struct_name param_name)" (declared at line N).
    This is a false positive; the program compiles without any errors (tested with both GCC and Clang).

    When the function is defined right away, without any previous prototype declaration, the error is not issued.

    Also, when the nested struct parameter is a value, not a pointer, then passing in a valid value will issue the error: argument of type "struct struct_name" is incompatible with parameter of type "struct struct_name".
    This happens regardless of the function being marked static or not, and also regardless of the function prototype being declared before defining it.

Steps to reproduce

  1. Create a C file
  2. Declare a struct that is nested inside another struct or union
  3. Declare (not define, though a definition can be written later and the bug still persists) a function that is marked static and has the nested struct as a parameter (value or pointer)
  4. See error

Expected behavior

False positive; expected no errors.

Code sample and logs

  • Code sample

    struct foo {
    	long l;
    
    	struct bar {
    		int i;
    	} bar;
    };
    
    static void func(struct bar b);
    
    int main() {
    	struct bar b = {
    		.i = 0
    	};
    	func(b);
    }
    
    static void func(struct bar b) {}
  • No c_cpp_properties.json - everything default values

  • Logs from running C/C++: Log Diagnostics from the VS Code command palette

    -------- Diagnostics - 2/1/2022, 11:06:17 AM
    Version: 1.8.3
    Current Configuration:
    {
        "name": "Linux",
        "includePath": [
            "${workspaceFolder}/**"
        ],
        "defines": [],
        "compilerPath": "/usr/local/bin/gcc",
        "cStandard": "gnu17",
        "cppStandard": "gnu++17",
        "intelliSenseMode": "linux-gcc-x64",
        "compilerArgs": [],
        "intelliSenseModeIsExplicit": false,
        "cStandardIsExplicit": false,
        "cppStandardIsExplicit": false,
        "mergeConfigurations": false,
        "compilerPathIsExplicit": false,
        "browse": {
            "path": [
                "${workspaceFolder}/**"
            ],
            "limitSymbolsToIncludedHeaders": true
        }
    }
    Translation Unit Mappings:
    [ /tmp/tmp.ZXVQY0SYhg/main.c ]:
        /tmp/tmp.ZXVQY0SYhg/main.c
    Translation Unit Configurations:
    [ /tmp/tmp.ZXVQY0SYhg/main.c ]:
        Process ID: 32470
        Memory Usage: 11 MB
        Compiler Path: /usr/local/bin/gcc
        Includes:
            /usr/local/lib/gcc/x86_64-pc-linux-gnu/12.0.0/include
            /usr/local/include
            /usr/local/lib/gcc/x86_64-pc-linux-gnu/12.0.0/include-fixed
            /usr/include/x86_64-linux-gnu
            /usr/include
        Standard Version: c17
        IntelliSense Mode: linux-gcc-x64
        Other Flags:
            --gcc
            --gnu_version=120000
    Total Memory Usage: 11 MB
    
    ------- Workspace parsing diagnostics -------
    Number of files discovered (not excluded): 16661
    
  • Logs from the language server logging

    loggingLevel: Debug
    loggingLevel has changed to: Debug
    cpptools/didChangeCppProperties
    $/setTraceNotification
    cpptools/getCodeActions: /tmp/tmp.ZXVQY0SYhg/main.c (id: 312)
    cpptools/textEditorSelectionChange
    cpptools/getDocumentSymbols: /tmp/tmp.ZXVQY0SYhg/main.c (id: 313)
    cpptools/getDocumentSymbols
    cpptools/textEditorSelectionChange
    cpptools/activeDocumentChange: /tmp/tmp.ZXVQY0SYhg/main.c
    cpptools/getCodeActions: /tmp/tmp.ZXVQY0SYhg/main.c (id: 314)
    idle loop: reparsing the active document
    Checking for syntax errors: /tmp/tmp.ZXVQY0SYhg/main.c
    Queueing IntelliSense update for files in translation unit of: /tmp/tmp.ZXVQY0SYhg/main.c
    cpptools/textEditorSelectionChange
    cpptools/finishUpdateSquiggles
    Error squiggle count: 2
    Update IntelliSense time (sec): 0.256
    cpptools/getSemanticTokens: /tmp/tmp.ZXVQY0SYhg/main.c (id: 315)
    willSaveWaitUntil: 0ms
    textDocument/didSave: /tmp/tmp.ZXVQY0SYhg/main.c
      tag parsing file: /tmp/tmp.ZXVQY0SYhg/main.c
    cpptools/fileChanged: /tmp/tmp.ZXVQY0SYhg/main.c
    idle loop: reparsing the active document
    Checking for syntax errors: /tmp/tmp.ZXVQY0SYhg/main.c
    Queueing IntelliSense update for files in translation unit of: /tmp/tmp.ZXVQY0SYhg/main.c
    cpptools/finishUpdateSquiggles
    Error squiggle count: 2
    Update IntelliSense time (sec): 0.252
    cpptools/getSemanticTokens: /tmp/tmp.ZXVQY0SYhg/main.c (id: 317)
    

Screenshots

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Language ServiceVisual StudioInherited from Visual StudiobugfixedCheck the Milestone for the release in which the fix is or will be available.verifiedBug has been reproduced

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions