microsoft / microsoft/vscode-cpptools

Autocomplete fails for templated class/struct

Open
#5,039 6 comments 21 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature: Auto-complete Language Service more votes needed Visual Studio
Dominant language
TypeScript
Stars
6.2k
Forks
1.7k
Avg merge
14h 46m
Merged PRs (30d)
61

Description

Type: LanguageService

Describe the bug

  • OS and Version: MacOS Mojave 10.14.6
  • VS Code Version: 1.42.1
  • C/C++ Extension Version: 0.26.3
  • Other extensions you installed (and if the issue persists after disabling them):
  • A clear and concise description of what the bug is.

intelliSense autocomplete fails to deduce type of templated class declared in templated class/function.

To Reproduce

namespace ID {
template <typename T>
struct addingClass {
  public:
    addingClass(T a, T b) : result(a + b) {}
    const T result;
};

template <typename T>
class TemplatedClass {
  public:
    static T add(T a, T b) {
        auto addition = addingClass<T>(a, b);
        auto result = addition.result; // intelliSense provides not provide auto-complete for addingClass::result member
        return result;
    }
};
}

int main() {
    return ID::TemplatedClass<int>::add(-1, 1);
}

Hovering over the addition variable shows auto addition, and line 14 fails to auto-complete the result class member.

Expected behavior

I would expect auto-complete to deduce the class members of the addingClass in the above example.

Screenshots

Screen Shot 2020-03-02 at 3 08 36 PM

Screen Shot 2020-03-02 at 3 08 50 PM

Additional context

c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [],
            "compilerPath": "/usr/local/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64",
            "configurationProvider": "vector-of-bool.cmake-tools"
        }
    ],
    "version": 4
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the autocomplete failure with the templated C++ example and the provided c_cpp_properties.json configuration in the C/C++ extension. Trace the language-service handling of the addition variable and template type deduction; done means autocomplete recognizes the addingClass::result member.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
developer-experience
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.