Skip to content

Intellisense not working properly when template class is defined in cpp file (0.26.0-insiders3) #4424

Closed

Description

Type: LanguageService

Intellisense failing to auto-complete in template class function definitions in cpp files when auto-complete target is included after template class declaration header file. This is hard-to describe, so let me illustrate instead;

Consider we have following header files

foo.hpp

#pragma once

// template class declaration, no definition provided
template<typename T>
struct foo{
    void do_foo();
};

bar.hpp

#pragma once

struct bar{
    void do_bar();
};

And I want to define foo class in cpp file, foo.cpp

foo.cpp

#include "foo.hpp"
#include "bar.hpp"

// foo template class definition
template<typename T>
void foo<T>::do_foo(){
    bar x;
    // here, intellisense fails to show do_bar() when x. is pressed
    x.do_bar(); 
}

But when the order of the includes are changed, the problem disappears

foo.cpp (order change)

#include "bar.hpp" // include bar first
#include "foo.hpp"

// template definition
template<typename T>
void foo<T>::do_foo(){
    bar x;
    // works as expected, intellisense shows do_bar() in autocomplete box
    x.do_bar(); 
}

Another interesting point is, this only happens when foo is a template class. When I declare foo as a regular class/struct, problem disappears. So my best guess is, intellisense somehow acts as if foo template class is being defined in a header file. In that scenario, this outcome would make sense. But, this shouldn't be the case when defining foo in cpp file.

Expected behavior

Intellisense should be able to auto-complete the declarations included after declaration of template class, when definition of template class is made in other file. The order of includes should not affect the autocomplete suggestions when described scenario is in effect.

*System details

VSCode

  • Version: 1.40.0-insider
  • Commit: 72bc289d32ec4f867e73b7f1f2a22f7d614ae2bb
  • Date: 2019-10-11T05:31:05.355Z
  • Electron: 6.0.12
  • Chrome: 76.0.3809.146
  • Node.js: 12.4.0
  • V8: 7.6.303.31-electron.0
  • OS: Linux x64 4.19.0-4-amd64 (debian sid)

C/C++ Extension

Version: 0.26.0-insiders3
Current Configuration:
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++20",
"intelliSenseMode": "gcc-x64",
"configurationProvider": "vector-of-bool.cmake-tools",
"browse": {
"limitSymbolsToIncludedHeaders": false,
"path": [
"${workspaceFolder}/
"
]
},
"compilerArgs": []
}

Activity

  1. Colengms commented on Oct 14, 2019

    @Colengms
    Contributor

    Hi @mustafakemalgilor . Thanks for reporting this.

    I'm able to repro in VS, with gcc IntelliSense Mode. (VS and the VS Code C/C++ extension share some common code for IntelliSense).

    I've opened a bug against VS here for tracking: https://developercommunity.visualstudio.com/content/problem/776487/incorrect-intellisense-in-clang-or-gcc-mode-with-t.html

  2. Colengms commented on Oct 22, 2020

    @Colengms
    Contributor

    The linked bug in VS was fixed, but the issue still repro's with the C/C++ Extension, for some reason.

  3. moved this from Triage to No status in cpptoolson Jun 20, 2024
  4. Colengms commented on Dec 17, 2024

    @Colengms
    Contributor

    Not sure when this got fixed, but I'm unable to repro with 1.23.2. Closing as fixed.

  5. locked and limited conversation to collaborators on Jan 31, 2025
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

    No type

    Projects

    • Status
      Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions