microsoft / microsoft/vscode-cpptools

Type of array/vector incorrect in IntelliSense after a typedef and another array/vector

Open
#7,778 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug 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

Bug type: Language Service

Describe the bug

  • OS and Version: Windows 11 Pro
  • VS Code Version: 1.57.1
  • C/C++ Extension Version: 1.5.0-insiders3
    In some cases the type of the elements of an array/vector is incorrect in IntelliSense after a typedef and another array/vector.

Steps to reproduce

  1. Paste the following code into a cpp file:
#include <vector>

typedef int my_type;
std::vector<my_type> v;

void f(std::vector<int> x) {}
  1. Hover over the f (or x).
  2. The tooltip says x is a std::vector<my_type>.
  3. Notice how under Outline it is displayed as std::vector<float>.

Expected behavior
x should be a std::vector<float>.

A more general way to reproduce this is:

  1. Define a new type: typedef <existing_type> <new_type>;
  2. Define an array/vector of <new_type>.
  3. Define a function/variable that is/has an array/vector of <existing_type>.
  4. IntelliSense will tell it is an array/vector of <new_type>.

Screenshots
image
image

Additional context
Visual Studio 2019 seems to have the same issue.

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 with the C++ language service IntelliSense handling for typedefs and std::vector or array types, using the reproduction snippet in the issue. Verify the hover tooltip and Outline display for the function parameter, and consider the bug done when both report the correct element type without being affected by the preceding typedef and vector.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.