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

__cplusplus implied? #884

Closed
decimad opened this issue Jul 14, 2017 · 13 comments
Closed

__cplusplus implied? #884

decimad opened this issue Jul 14, 2017 · 13 comments
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service

Comments

@decimad
Copy link

decimad commented Jul 14, 2017

I'm facing an issue with headers which would put typedefs into some namespace in case the header is compiled withing a c++ compilation unit. Now I'm working with C-Code which uses those typedefs, but the parset cannot locate them, since it parsed the header as C-Code.
Is there a way to suppress __cplusplus while parsing?

@sean-mcmanus sean-mcmanus added Language Service more info needed The issue report is not actionable in its current state labels Jul 14, 2017
@sean-mcmanus
Copy link
Contributor

What parser are you referring to? The Default IntelliSense engine, the Tag Parser, or the parser you use for compiling? Does #undef work?

@decimad
Copy link
Author

decimad commented Jul 14, 2017

Im using the "Default" parser which I understand to be the IntelliSense engine as opposed to the Tag parser.
I did not try to put an #undef there, since I figured removing the namespace-stuff temporarily was the safe bet.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Jul 14, 2017

Is the translation unit C or C++? You should not have __cplusplus defined if your file type is .c (or registered as a "c" language file in files.associations). The IntelliSense parser has a C and C++ mode, so if __cplusplus is defined, it sounds like it's using the wrong mode. I think we need more info for a repro.

@decimad
Copy link
Author

decimad commented Jul 14, 2017

Well, all the CUs are .c, the types are defined in headers though. So if it is as you say, it might be that the connection is somehow not made to deduce parsing those headers as plain c - which could mean that I'm setting something up incorrectly? I will try to come up with more details after investigation during the weekend.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Jul 14, 2017

I'm still confused as to what error you're experiencing. If you cannot locate the typedefs in namespaces in C code, then that sounds correct, because C doesn't have namespaces. If you open a .c file, then __cplusplus shouldn't be defined, but it's possible if you open the .h file, the IntelliSense engine will compile the header into a C++ translation unit (if it fails to match it up with the .c file, i.e. if it chose another .cpp file that included the header or fell back to a dummy C++ translation unit).

@decimad
Copy link
Author

decimad commented Jul 14, 2017

The .c file includes a header whose typedefs are declared inside a namespace iff __cplusplus is defined. In this situation type references inside .c file are squiggled. When I then remove the namespace-stuff from the header, the .c file doesn't show squiggles anymore. During all that time the CMake-Build works perfectly (like in the other issue)
Just answering your question quickly, I will still investigate this further to give more "educated" informations.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Jul 14, 2017

It shows "C" and not "C++" in the bottom right corner when you open the .c file, right? If you use class c {}; and get `identifier "class" is undefined" then it means the translation unit is correctly treated as C code by our IntelliSense engine, and some external file is #defining the __cplusplus (Go to Definition might work to find the culprit); otherwise, if no errors occur, the code is incorrectly being processed as C++ and we'd want to find a repro.

@decimad
Copy link
Author

decimad commented Jul 20, 2017

Okay, I cannot come up with a real explanation, but sometimes .c source files get classified as c++ even though I did nothing related to setting up/overriding the extension defaults. More often it happens regularly that headers are classified as being c++. But this all rather seems to come from a "bad" interaction between the c++ tools, the cmake integration as well as the cmake-helper which serves as the gluing. Bad things happen most of the times at the time when the cmake-integration falls back to the "all" target (I could not yet find a reason why it does that all the time), at which point the cmake-helper can't deduce include paths anymore etc.. So I don't really think that it is a problem of the cpptools per se.

@sean-mcmanus
Copy link
Contributor

We have seen the bug were a .c file gets added as a "cpp" file (seems to happen only in special situations), so we'll try to find a repro (and/or review the code) and fix it.

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Jul 20, 2017

The bug where .c/cpp files can get associated with the wrong "cpp"/"c" language has been fixed for the next update.

@sean-mcmanus sean-mcmanus added fixed Check the Milestone for the release in which the fix is or will be available. and removed more info needed The issue report is not actionable in its current state labels Jul 20, 2017
@decimad
Copy link
Author

decimad commented Jul 21, 2017

Great! Sorry I could not come up with a reliable repro :( Is there maybe something I can do to circumvent this beheviour until then?

@sean-mcmanus
Copy link
Contributor

That's fine. I found the repro myself. Our fix is in the exececutable, but you can add a workaround via adding javascript code to the out/src/LanguageServer/C_Cpp.js addFileAssociations method, such as if (file.endsWith(".c") || file.endsWith(".cpp")) continue;, before the file gets added to the assoc array.

@bobbrow bobbrow added the bug label Jul 25, 2017
@bobbrow
Copy link
Member

bobbrow commented Aug 3, 2017

We released the fix yesterday. Please install version 0.12.2.

@bobbrow bobbrow closed this as completed Aug 3, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Oct 17, 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

3 participants