Skip to content

Breadcrumb not working correctly when using macros #9224

@Mega-Wolf

Description

@Mega-Wolf

Bug type: Language Service

Keywords: Breadcrumb, Macro, sizeof

(I assume these two won't matter)

  • OS and Version: Windows 10
  • VS Code Version: 1.65.2

(aka the newest official one)

  • C/C++ Extension Version: 1.9.8

So, I had this bug for quite a long time now and searching for open issues with "breadcrumbs" only yielded 3 results; neither of which fitted this one.

I have this combination of macros I use all the time for iterating arrays and they always break the breadcrumbs; see the image below; I cannot exactly pinpoint the reason why it breaks. My original idea was that it had to do with nested macros, but that doesn't fit Func3b vs. Func3c.

image

Here is how the breadcrumbs look like:
image

While this is annoying, it gets REALLY annoying, if the function using the macro does other stuff as well; here I added Func7 at the end, that also declares a variable and calls a function

image

Below is the C/C++ log:

-------- Diagnostics - 22.4.2022, 14:17:55
Version: 1.9.8
Current Configuration:
{
    "name": "Win64",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [
        "_DEBUG"
    ],
    "windowsSdkVersion": "10.0.17763.0",
    "cStandard": "c11",
    "cppStandard": "c++17",
    "intelliSenseMode": "msvc-x64",
    "compilerPathIsExplicit": false,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "macFrameworkPath": [],
    "compilerArgs": [],
    "mergeConfigurations": false,
    "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe",
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ C:\Users\Tobia\Documents\Programs\GUITest\code\dummy.cpp ]:
    C:\Users\Tobia\Documents\Programs\GUITest\code\dummy.cpp
Translation Unit Configurations:
[ C:\Users\Tobia\Documents\Programs\GUITest\code\dummy.cpp ]:
    Process ID: 21196
    Memory Usage: 15 MB
    Compiler Path: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe
    Includes:
        C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2019\BUILDTOOLS\VC\TOOLS\MSVC\14.29.30037\INCLUDE
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UM
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\UCRT
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\SHARED
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\WINRT
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.19041.0\CPPWINRT
    Defines:
        _DEBUG
    Standard Version: ms_c++17
    IntelliSense Mode: windows-msvc-x64
Total Memory Usage: 15 MB

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

And here are the contents of the file:

#define inc0(varname, max) for (int varname = 0; varname < max; ++varname)
#define ArrayCount(array) (sizeof(array) / sizeof((array)[0]))

// NOTE: This is like ArrayCount but without the parenthesis (just for testing the breadcrumbs)
#define ArrayCount2(array) sizeof(array) / sizeof((array)[0])

int MyArray[10];

void Func1() {
    // No macro; WORKS
    for (int i = 0; i < (sizeof(MyArray) / sizeof((MyArray)[0])); ++i) {
        MyArray[i] = 4;
    }
}

void Func2() {
    // Only ArrayCount; WORKS
    for (int i = 0; i < ArrayCount(MyArray); ++i) {
        MyArray[i] = 4;
    }
}

void Func3a() {
    // Only inc0, with int; WORKS
    inc0 (i,   10) {
        MyArray[i] = 4;
    }
}

void Func3b() {
    // Only inc0, with resolved ArrayCount; BREAKS
    inc0 (i,   (sizeof(MyArray) / sizeof((MyArray)[0]))) {
        MyArray[i] = 4;
    }
}

void Func3c() {
    // Only inc0, with resolved ArrayCount (but without parenthesis around); WORKS
    inc0 (i,   sizeof(MyArray) / sizeof((MyArray)[0])) {
        MyArray[i] = 4;
    }
}

void Func4() {
    // Both macros; BREAKS
    inc0 (i,   ArrayCount(MyArray)) {
        MyArray[i] = 4;
    }
}

void Func5() {
    // inc0, ArrayCount2; BREAKS
    inc0 (i,   ArrayCount2(MyArray)) {
        MyArray[i] = 4;
    }
}

void Func6() {
    int whatever = 0;
}

void Func7() {
    inc0 (i,   ArrayCount(MyArray)) {
        MyArray[i] = 4;
    }

    int a = 0;
    Func1();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature: Document SymbolOutline view and breadcrumbsLanguage 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