Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function definitions missing from intellisense in Visual Studio C++ 2005-2013

The following problem plagues one of my projects for a long time:

Some function definitions (from .cpp files) are excluded/hidden from intellisense!

It is not possible to "Goto Definition" for those functions, nor are the listed in the Navigation Bar.

The functions do appear in the autocompletion list, though. The problem is for .cpp files only, the .h files are parsed fine. 'Goto Declaration' works, too.

This is the same since 2005, with every new version, I was hoping for a fix, but it does not seem to be regognized as a bug by anyone else.

UPDATE: I have tracked this down to the following: All functions containing a certain macro are not recognized by intellisense. The original macro was

#define forlist(x,list) for( auto x= list.begin(); x.valid(); ++x)

but you can also use the simplified test case

#define fortest(x)  for( auto x= 1; x< 2; ++x)

void myclass::TestFN()
{
    fortest( g )
    {
        g;
    }
}

Next step would be to find a workaround (or try to go through micrsoft bug reporting).

Please don't rant too much about this macro. This is existing code of a list implementation which I am not able to change. I could just NOT use the macro, but I still think this is a VS bug.

One funny thing is, that the following (really ***ic macro) works fine:

#define fortest(x)  for( auto x= 1; x< 2; ++x) {

void myclass::TestFN()
{
    fortest( g )
        g;
    }
}

Could it be that intellisense treats case 1 as an illegal local function definition? (see http://connect.microsoft.com/VisualStudio/feedback/details/781121/c-intellisense-mistakes-loop-expression-for-function-definition)

The following work fine, too

#define fortest(x)  for( auto x= 1; x< 2; ++x)

void myclass::TestFN()
{
    fortest( g )
        g;
}
like image 644
nuu Avatar asked Jan 31 '14 12:01

nuu


People also ask

How do I enable IntelliSense in Visual Studio?

To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.

How do I restart IntelliSense Visual Studio?

For Visual Studio 2017 (and I think Visual Studio 2019 also), close Visual Studio, go into the . vs folder in your projects folder and delete all the contents apart from the . suo file, then reopen Visual Studio. This way you can rebuild the Intellisense cache without losing your preferences.

How do I enable IntelliSense in Visual Studio 2015?

I would try: In Visual Studio 2015, go to 'Tools | Options | Text Editor | C# | General both "Auto list members" and "Parameter information" should be checked. If that doesn't work I would try to disable ReSharper in VS2013 and try to get the normal intellisense working.


1 Answers

As usual, interest in my question ebbed up after a couple of hours, so I had to figure it out by myself...

We just have to use the concept of cpp.hint files.

Basically you have to put the troublesome macros into a file named cpp.hint and put that file in your solution directory (which did not work for me) OR in a parent-directory where your code files reside in. (worked for me)

In that file we just put the troublesome macros WITHOUT right-hand-side, so e.g.:

#define forlist(x,list)

NOTE: Your must reset IntelliSense cache for use new data from changed cpp.hint file. You should:

  • delete ipch folder (usually placed in Solution folder).
  • delete all *.sdf files in Solution folder.
  • delete all *.VC.db files in Solution folder or in ipch folder.

For more advanced macros (like having 'start' and 'end' macros for code blocks), there are some other tricks.

The original link is: http://msdn.microsoft.com/en-us/library/dd997977.aspx

The reason for the trouble is that Intellisense performance would (potentially) decrease dramatically if it had to parse all macros in a project, so it only parses those given explicitly in 'cpp.hint'.

like image 122
nuu Avatar answered Oct 17 '22 11:10

nuu