Skip to content

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

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

Activity

  1. sean-mcmanus commented on Apr 21, 2025

    @sean-mcmanus
    Contributor

    Tony Lechner (@tonymke) It appears the original issue #8751 was never actually fixed (i.e. I get the same bug still with 1.10.5). I've re-activated the internal VS issue 1469927 .

  2. Johnrobmiller commented on Jul 28, 2025

    @Johnrobmiller

    I also found this bug. For me, all I needed to do was reload the window (ctrl+shift+P, select "reload window"). However, I can't guarantee this work work for anybody else.

    More information for the maintainers: this bug replicated when I moved a bunch of structs from one header file to another and tried to update all the "#include" calls in all my files.

  3. MCJack123 commented on Feb 9, 2026

    @MCJack123

    I'm also experiencing this issue when using a pointer to an incomplete structure without a corresponding struct declaration. It only occurs in C mode (it's configured for C89 mode), and goes away if I add struct luaL_Reg; to the top of my code. The code compiles fine with a warning in GCC.

    Image Image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    • Status
      No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions