microsoft / microsoft/vscode-cpptools

Incorrect intelliSense errors depending on include order

Open
#9,540 13 comments 13 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 10 21H2
  • VS Code Version: 1.68.1
  • C/C++ Extension Version: 1.10.7
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).

I've got the following two files, using IAR Systems standard library headers:

// main.cpp
#include <stdint.h>
#include <wchar.h>
#include <memory>

#include "header.hpp"
int main() {
  auto b = ns::B(1);
}

// header.hpp
#pragma once

namespace ns {
  class B {
    public:
      explicit B(const int& a) {}
  };
}

In main.cpp, intelliSense incorrectly complains that the namespace ns does not exist:
image
If I open header.hpp, where ns is defined, and go back to main.cpp, the error disappears for a while. If I browse some other files for a while, the error reappears.

Interestingly, the problem only occurs when <memory> is included last of the standard library headers. Removing any of the includes or including <memory> earlier gets rid of the intelliSense error. main.cpp compiles correctly in all cases.

Steps to reproduce
Here is an example that reproduces the problem:
cpptools_errors_from_include_order_example.zip
It includes all the necessary files, including the c_cpp_properties.json and all required IAR standard library headers.

Simply open main.cpp and observe the intelliSense error.

Additional context
This may be related to https://github.com/microsoft/vscode-cpptools/issues/9170. The symptoms are similar, but the workaround of disabling the cache size limit did not work for me.

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

Open the supplied cpptools_errors_from_include_order_example.zip and inspect main.cpp, header.hpp, c_cpp_properties.json, and the IAR headers; start by reproducing the false ns error with included last. Done means IntelliSense no longer reports that ns does not exist for the provided example, while the project still compiles correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, typescript, vscode
Domain
developer-experience, devtools
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.