Skip to content

False positive declaration-is-incompatible in C on static function that takes a tagged struct type defined within another struct #13536

@tonymke

Description

@tonymke

Environment

  • OS and Version: Arch Linux x64, fully up-to-date
  • VS Code Version: 1.99.3
  • C/C++ Extension Version: 1.24.5
  • If using SSH remote, specify OS of remote machine: N/A

Bug Summary and Steps to Reproduce

Bug Summary:
In C, if a static function takes a struct that was defined within another struct, a false positive declaration-is-incompatible problem appears.

Regression of #8751

Steps to reproduce:

  1. With the C/C++ extension installed and running, open a C file that contains a tagged structure defined within another tagged structure, and a static function which accepts a parameter of that nested tagged structure type. (example included below):
  2. Validate that file compiles and executes as expected.

Expected behavior:
No problem is noted

Actual behavior:
A "declaration is incompatible" problem appears.

declaration is incompatible with "int print_foo_bar_static(const struct foo_bar *fbp)" (declared at line 33)

Configuration and Logs

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Diagnostics:

-------- Diagnostics - 4/19/2025, 11:10:46 AM
Version: 1.24.5
Current Configuration:
{
    "name": "Linux",
    "includePath": [
        "/home/tony/src/asdf/**"
    ],
    "defines": [],
    "compilerPath": "/usr/bin/gcc",
    "cStandard": "c17",
    "cppStandard": "c++17",
    "intelliSenseMode": "linux-gcc-x64",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "compilerPathInCppPropertiesJson": "/usr/bin/gcc",
    "mergeConfigurations": false,
    "recursiveIncludes": {
        "reduce": "default",
        "priority": "afterSystemIncludes",
        "order": "depthFirst"
    },
    "browse": {
        "limitSymbolsToIncludedHeaders": true
    }
}
Modified Settings:
{
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.function": "newLine",
    "C_Cpp.vcFormat.newLine.beforeOpenBrace.block": "sameLine",
    "C_Cpp.clang_format_fallbackStyle": "GNU"
}
Additional Tracked Settings:
{
    "editorTabSize": 8,
    "editorInsertSpaces": false,
    "editorAutoClosingBrackets": "languageDefined",
    "filesEncoding": "utf8",
    "filesAssociations": {
        "*.h": "c"
    },
    "filesExclude": {
        "**/.git": true,
        "**/.svn": true,
        "**/.hg": true,
        "**/.DS_Store": true,
        "**/Thumbs.db": true
    },
    "filesAutoSaveAfterDelay": false,
    "editorInlayHintsEnabled": true,
    "editorParameterHintsEnabled": true,
    "searchExclude": {
        "**/node_modules": true,
        "**/bower_components": true,
        "**/*.code-search": true
    },
    "workbenchSettingsEditor": "ui"
}
cpptools version (native): 1.24.5.0
Current database path: /home/tony/.cache/vscode-cpptools/3c2dde7ab04cc03895f85c14d63a05eb/.browse.VC.db
Translation Unit Mappings:
[ /home/tony/src/asdf/main.c - source TU]:
    /usr/include/bits/types/FILE.h
    /usr/include/bits/typesizes.h
    /usr/include/stdio.h
    /usr/include/stdlib.h
    /usr/include/sys/cdefs.h
    /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include/stddef.h
Translation Unit Configurations:
[ /home/tony/src/asdf/main.c ]
    Process ID: 29641
    Memory Usage: 23 MB
    Compiler Path: /usr/bin/gcc
    Include paths:
        system include: /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include
        system include: /usr/local/include
        system include: /usr/lib/gcc/x86_64-pc-linux-gnu/14.2.1/include-fixed
        system include: /usr/include
    Standard Version: c17
    IntelliSense Mode: linux-gcc-x64
    Other Flags:
        --gcc
        --gnu_version=140201
Total Memory Usage: 23 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 34569

C/C++ Extension Debug logs: attached, see "Additional context"

Other Extensions

No response

Additional context

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

struct foo {
	struct foo_bar {
		int x, y;
	} bar;
};

int print_foo_bar(const struct foo_bar *fbp);
static int print_foo_bar_static(const struct foo_bar *fbp); /* problem appears here */

int main(void)
{
	struct foo foo = { {1, 1} };

	if (print_foo_bar(&foo.bar) < 0) {
		exit(EXIT_FAILURE);
	}

	if (print_foo_bar_static(&foo.bar) < 0) {
		exit(EXIT_FAILURE);
	}
}

int print_foo_bar(const struct foo_bar *fbp)
{
	assert(fbp != NULL);
	return printf("%p->%d.%d\n", fbp, fbp->x, fbp->y);
}

static int print_foo_bar_static(const struct foo_bar *fbp)
{
	assert(fbp != NULL);
	return printf("%p->%d.%d\n", fbp, fbp->x, fbp->y);
}
[tony@framework asdf]$ cc -std=c99 -o asdf main.c && ./asdf; echo $?
0x7fff78f88d70->1.1
0x7fff78f88d70->1.1
0

Image

extension_logs.txt

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions