microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.4k stars 1.51k forks source link

No suggestions when accessing member function of a templated struct #10295

Closed rohanbari closed 1 year ago

rohanbari commented 1 year ago

Environment

Bug Summary and Steps to Reproduce

Bug Summary: There are no name suggestions of a function defined in the same templated struct from where it is being accessed.

Steps to reproduce:

  1. Create a cpp file.
  2. Write down the attached code.
  3. Delete and type ::calculateHash.
  4. See no suggestions even when Ctrl+Space is pressed.

Expected behavior: The member function calculateHash should have been displayed in the suggestion along with its parameter information as a usual function would do.

Configuration and Logs

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": ["${workspaceFolder}/**"],
            "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
            "compilerPath": "C:/TDM-GCC-64/bin/g++.exe",
            "cStandard": "c99",
            "cppStandard": "c++20",
            "intelliSenseMode": "windows-gcc-x64",
            "compilerArgs": ["-O3", "-pedantic", "-Wall", "-Wextra"]
        }
    ],
    "version": 4
}

C/C++: Log Diagnostics

-------- Diagnostics - 12/17/2022, 8:33:33 AM
Version: 1.13.8
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "compilerPath": "C:/TDM-GCC-64/bin/g++.exe",
    "cStandard": "c99",
    "cppStandard": "c++20",
    "intelliSenseMode": "windows-gcc-x64",
    "compilerArgs": [
        "-O3",
        "-pedantic",
        "-Wall",
        "-Wextra"
    ],
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Translation Unit Mappings:
[ C:\Users\Rohan\Desktop\code\CPlusPlus\src\templates\Concepts.cpp ]:
    C:\Users\Rohan\Desktop\code\CPlusPlus\src\templates\Concepts.cpp
[ C:\Users\Rohan\Desktop\code\CPlusPlus\src\1.cpp ]:
    C:\Users\Rohan\Desktop\code\CPlusPlus\src\1.cpp
Translation Unit Configurations:
[ C:\Users\Rohan\Desktop\code\CPlusPlus\src\templates\Concepts.cpp ]:
    Process ID: 8172
    Memory Usage: 114 MB
    Compiler Path: C:\TDM-GCC-64\bin\g++.exe
    Includes:
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\x86_64-w64-mingw32
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\backward
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include
        C:\TDM-GCC-64\include
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include-fixed
        C:\TDM-GCC-64\x86_64-w64-mingw32\include
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: c++20
    IntelliSense Mode: windows-gcc-x64
    Other Flags:
        --g++
        --gnu_version=100300
[ C:\Users\Rohan\Desktop\code\CPlusPlus\src\1.cpp ]:
    Process ID: 10012
    Memory Usage: 119 MB
    Compiler Path: C:\TDM-GCC-64\bin\g++.exe
    Includes:
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\x86_64-w64-mingw32
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include\c++\backward
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include
        C:\TDM-GCC-64\include
        C:\TDM-GCC-64\lib\gcc\x86_64-w64-mingw32\10.3.0\include-fixed
        C:\TDM-GCC-64\x86_64-w64-mingw32\include
    Defines:
        _DEBUG
        UNICODE
        _UNICODE
    Standard Version: c++20
    IntelliSense Mode: windows-gcc-x64
    Other Flags:
        --g++
        --gnu_version=100300
Total Memory Usage: 233 MB

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

Other Extensions

cschlosser.doxdocgen@1.4.0
dbaeumer.vscode-eslint@2.2.6
eamodio.gitlens@13.1.1
esbenp.prettier-vscode@9.10.3
GitHub.github-vscode-theme@6.3.2
isudox.vscode-jetbrains-keybindings@0.1.9
ms-python.isort@2022.8.0
ms-python.python@2022.20.1
ms-python.vscode-pylance@2022.12.20      
ms-toolsai.jupyter@2022.11.1003412109    
ms-toolsai.jupyter-keymap@1.0.0
ms-toolsai.jupyter-renderers@1.0.12
ms-toolsai.vscode-jupyter-cell-tags@0.1.6
ms-toolsai.vscode-jupyter-slideshow@0.1.5
ms-vscode.cmake-tools@1.12.27
ms-vscode.cpptools@1.13.8
PKief.material-icon-theme@4.23.0
platformio.platformio-ide@2.5.5
ritwickdey.LiveServer@5.7.9
twxs.cmake@0.0.17

Additional context

Here is the code sample:

#include <iostream>

// This will be the type of hash.
using UInt = unsigned int;

template <int length>
struct SDBM {
    constexpr static UInt calculateHash(const char* const hash, UInt& value)
    {
        // Remove ::calculateHash... and try typing again with Ctrl+Space for suggestions.
        // However, it is a valid code.
        UInt ch {SDBM<length - 1>::calculateHash(hash, value)};
        value = ch + (value << 6) + (value << 16) - value;

        return hash[length - 1];
    }
};

int main()
{
    /* code */
    return EXIT_SUCCESS;
}

Relevant screenshot:

Unexpected output

michelleangela commented 1 year ago

@rohanbari Thank you for reporting this issue and providing logs and sample code. We determined that this is a duplicate of https://github.com/microsoft/vscode-cpptools/issues/5039. This is an issue inherited from shared code with Visual Studio's C++ code base and a bug has been filed against VS at https://developercommunity.visualstudio.com/t/intellisense-instance-of-template-stored-in-auto-d/936260. Please upvote that VS ticket to increase its priority.