Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not Go to Definition/Parameter hinting for stdlib.h functions #578

Closed
wgj opened this issue Mar 19, 2017 · 8 comments
Closed

Can not Go to Definition/Parameter hinting for stdlib.h functions #578

wgj opened this issue Mar 19, 2017 · 8 comments
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service

Comments

@wgj
Copy link

wgj commented Mar 19, 2017

VSCode: 1.10.2
cpptools: 0.10.4
MacOS: 10.12.3

I've noticed there's a lot of similar issues for this, but a lot of them are confounded. Sorry in advance if there's an existing issue I should follow instead.

When I try to right click on a function in stdlib.h and select "Go to Definition", I get a tooltip-like error that no definition was found. "Go To Definition" with a function in stdio.h has expected behavior.

However, if I "Go to Definition" on #include <stdlib.h>, I'm given a choice between /usr/include/c++/4.2.1/tr1/stdlib.h and /usr/include/stdlib.h. Maybe this contributes/causes the issue.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    printf("contrived");
    exit(0);
}

STR

  1. Right click on exit().
  2. Select "Go to Definition", observe "No definition found for 'exit'.
@sean-mcmanus sean-mcmanus added Language Service more info needed The issue report is not actionable in its current state and removed more info needed The issue report is not actionable in its current state labels Mar 20, 2017
@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Mar 20, 2017

The definition is at /usr/include/c++/4.2.1/cstdlib, so opening that file should fix this, but we're still investigating why the file is sometimes not parsed automatically from the stdlib.h. There is no existing issue for this. It couldn't get a repro on 10.11.6, but I got repro on 10.12.3.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Mar 20, 2017

Okay, I got the repro on 10.11.6 too. The bug is caused by the fact that /usr/include/stdlib.h is being parsed instead of /usr/include/c++/4.2.1/tr1/stdlib.h . The file that isn't parsed has the #include to cstdlib, which contains the definition. Changing limitSymbolsToIncludedHeaders to false is a workaround. If we took the "tr1/" into account or parsed every matching file instead of the 1st match, that would fix this issue (or just set limitSymbolsToIncludedHeaders to false by default).

@wgj
Copy link
Author

wgj commented Mar 21, 2017

The bug is caused by the fact that /usr/include/stdlib.h is being parsed instead of /usr/include/c++/4.2.1/tr1/stdlib.h . The file that isn't parsed has the #include to cstdlib

For what it's worth, I'm working with C and not C++ code, so I would assume I want /usr/include/stdlib.h, and not /usr/include/c++/4.2.1/tr1/stdlib.h, but I'll defer to you.

@sean-mcmanus
Copy link
Contributor

That's good to know. Yeah, I thought you were using C++, so we have an additional problem then. The /usr/include/stdlib.h is being parsed, but it's not correctly picking up any of the symbols in the file. If I delete stuff in the file I can get symbols to be found, so there's something in the file that is causing our parser to fail. In the past this has been caused by macros. We'll investigate a fix...

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Mar 21, 2017

It's a problem with the attributes at the end of the exit definition. You can work around this via opening cpp.hint in /.vscode/extension/ms-vscode.cpptools-<version>/" and adding #define lines for all the attributes at the end of the definitions. We might be able to ship a fix with today's update. Let me know if we need to add more things to the list (I'm pretty sure we're missing stuff):

// Linux C lib
#define __THROW
#define __attribute_pure__
#define __nonnull(arg)
#define __wur
#define __attribute__(arg)
#define __attribute_warn_unused_result__
#define __attribute_malloc__

// Mac C lib
#define __dead2
#define __pure2
#define __result_use_check
#define __swift_unavailable(arg)
#define __scanflike(arg)
#define __printflike(arg)
#define __WATCHOS_PROHIBITED
#define __TVOS_PROHIBITED
#define __DARWIN_ALIAS(arg)
#define __DARWIN_ALIAS_C(arg)
#define __DARWIN_EXTSN(arg)
#define __OSX_AVAILABLE_STARTING(arg)
#define __OSX_AVAILABLE_BUT_DEPRECATED_MSG(arg)

Oh, and then you'll need to delete or rename your .browse.vc.db (or whatever you set your databaseFilename to).

@wgj
Copy link
Author

wgj commented Mar 21, 2017

fopen() was the only other I noticed (which I overlooked before, and leading to incorrect detail about only Intellisense parameter info for stdlib.h definitions), which adds __DARWIN_ALIAS_STARTING.

@sean-mcmanus
Copy link
Contributor

Ah, thanks, I missed that one. We'll fix that (either in the soon to be released update or the next one).

@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label Mar 23, 2017
@sean-mcmanus
Copy link
Contributor

Fixed with 0.10.5 for stdlib/stdio. We have a backlog item for investigating other standard headers which have similar problems with custom attributes.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Projects
None yet
Development

No branches or pull requests

2 participants