Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Go to Definition"/"Go to Declaration" not working reliably in VS2010?

I wanted to start contributing to an open source C++ project recently. Only having little experience with C++, I chose Visual Studio as IDE, updated with SP1. I got the solution to build relatively easily and wanted to navigate the code a little to get an overview.

This is when I noticed that sometimes "Go to Definition"/"Go to declaration" doesn't work. Both options are available when I right-click on a symbol in the source code, but when I'm in the header file, "Go to Definition" only takes me to the declaration again for those functions that are concerned. And when I'm in the .cc file, I always get taken to the definition in the same file.

Some more things I've noticed about the functions which are concerned by this are:

1) for some functions, I can navigate to the definition from the header file, but the other direction is broken

2) navigation for some functions can be fixed if the declaration is changed to completely match the definition, e.g.

header declaration:
    void buche(sint64 betrag, player_cost type);
source definition:
    void karte_t::buche(sint64 const betrag, player_cost const type)

change to

header declaration:
    void buche(sint64 const betrag, player_cost const type);

-> navigation works in both directions

3) when clicking into a code block of a concerned function in the source file, the scope menu at the top changes to "(Global Scope)" instead of showing the little arrow to the right (which is the symbol for a forward declaration I think?) and the class name (but those functions are definitely class members)

I've searched around a lot and this seems to be a relatively well-known problem. There's a thread here on the site: How to get IntelliSense to reliably work in Visual Studio 2008

I also found several threads on the Microsoft forums (which I can't link as I'm only allowed to post two hyperlinks), but no official confirmation of a bug or something.

The quintessence of the replies I found is that one should delete the .ncb file (which has been superseded by an .sdf database in VS2010 as I understand it), or use the option to rebuild the database on loading the solution. I did all of that multiple times, to no avail. The highest rated reply on the thread here on Stackoverflow seems to implicate that this is simply a bug (of Intellisense - did I get it right that it's this autocomplete component which is also responsible for the code navigation?) one has to accept, suggesting to use Visual Assist instead, however the question was about VS2008 then and one reply pointed to VS2010 improving on this. Another reply blamed recursive references, but I -think- this is not a problem in this project as all the files (certainly those few I've checked and encountered the problems with) have include guards. It has also been confirmed to me by one coder of that project that he has the same problems. But I'm not so keen on spending money on Visual Assist, it's only meant to be a little hobby ...

Having a lot of experience with Eclipse/Java, it just seems weird to me that such a relatively essential feature of an IDE doesn't work reliably. Of course I can understand that static code analysis is much more difficult for C++ than for Java. But then again, Visual Studio is a commercial product which has had a lot of development cycles.

So to sum this post up, is this an unavoidable bug?

like image 266
Hein Blöd Avatar asked Nov 04 '22 01:11

Hein Blöd


1 Answers

I'd guess that it depends on what you consider unavoidable.

In my experience, Intellisense issues seem to be caused mostly by either templates, macros, or both.

The parser/preprocessor that Intellisense uses doesn't seem to work in the same way as the compiler, and in some instances it is probably missing information and making wrong assumptions.

If you are coding and suddenly you notice that Intellisense is broken, and you have just added a rather complex template class (one which uses other template classes, or which you instance with another template-class, or anything weird), or a macro (again, especially, complex ones), you can normally assume that that is what caused it. Often, by rearranging the code, simplifying it a little, or just randomly changing it, you will be able to recover Intellisense (often only after you delete the .sdf file as well).

This is rather inconvenient, but if it's a library which broke it, it's worse. Some Boost libraries, particularly, have a tendency to break it rather often. In these cases, it's much harder to avoid.

Anyway, Intellisense is somewhat steadily improving. VS2010's is much more accurate and stable than VS2008's, and VS2012's seems to be better than VS2010's too (though I haven't used it much yet).

In fact, if you do not have any particular dependency on VS2010, you might want to just update to VS2012.

like image 138
Duther Avatar answered Nov 12 '22 11:11

Duther