Is your Intellisense behaving strange when project builds fine? Here are some tips that may help you. Edit: added one solution if project does not build successfully.
IDE: Microsoft Visual C++ 2019
Introduction
Have you ever had a project that would build fine, but VS Intellisense showed a bunch of errors which shouldn't be there? Or maybe you could not Go to Definition while it had a proper definition?
I want to share with you fixes and observations that did help me.
Be aware that these tips do not guarantee that your problem will be fixed, but if they do help, I will be very happy. about it!
Intellisense symptoms i managed to fix
- Project builds and works fine with red wavy lines all over the place.
- Selecting a declaration and trying Go to Definition but... (choose one of those: nothing happens, shows error
Definition not found
, jumps to completely wrong file/line, etc.). - Rename a symbol might claim that the symbol does not exist or there is a symbol ambiguity.
- Intellisense does not work for the whole file.
- Compiler error:
HWND
(possibly any other WinAPI type) is not a type name
.
Solution
-
The most important thing - start from scratch. Try to rewrite it in a 100% pure, working solution. Remove lines of code until the problem is gone. That's how i discovered the solution #6.
- So, the file has some problems. Does it belong to any project/solution? If yes, then ensure that the project/solution exists. But this existing is not enough for Intellisense - the project/solution must be in working condition (it must build without errors).
In my case intellisense ignored the file that was a part of a broken solution! I couldn't even open the solution (.sln file) because one of its project was using property sheet... that i deleted. So i removed the reference to that unexisting property sheet and the problem was fixed. - Go to Project -> _your_project_name Properties -> C/C++ -> General. To your right, there is a value Additional Include Directories. Make sure that all directories exist, otherwise VS Intellisense may complain at every
#include
statement. - You may heard of deleting .vs folder that sits in your Solution directory. It did help me in most cases with Go to Definition and Rename a symbol.
- It is a terrible workaround, but it may fix the behavior of VS Intellisense. So in my case, VS Intellisense just hates
static
symbols that are used outside of classes,structures and local scopes. Whenever I start to use static global functions/variables, I forget about VS Intellisense existence because it becomes so buggy that I cannot do anything about it. - Do all your functions have a name?
If you are working with WinAPI those 3 lines will never compile:
#include <windows.h>
HWND mainWnd; // compiler error E0757: variable "HWND" is not a type name
int (HWND); // a function without a name and with HWND as a parameter? WinAPI won't let you compile your project and Intellisense won't tell you what's wrong.
History
- 6th February, 2021: Article created
- 3rd June, 2021: Added 1st and 6th solution