-
Notifications
You must be signed in to change notification settings - Fork 629
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
C/C++: extern "c" will cause parse error #2647
Comments
It seems that your guessing is correct.
|
Well, if it fixes the problem and doesn't break tests then it looks good. However, I don't understand the relation between the #ifdef __cplusplus define and the #ifdef MAX one. |
My analysis is that it is related to how c parser handles extern "C" { }.
If cpreprocessor parser suppresses the area #ifdef __cplusplus ~ #end, c parser doesn't read the line extern "C" { and }. I have to add one more condition to the patch (#2647 (comment)). |
Close universal-ctags#2647. C parser doesn't work when C++ code "extern "C" {" and "}" is given. $ cat /tmp/extern-c.c extern "C" { #ifdef X void f() {} #else void g() {} #endif } $ u-ctags --output-format=xref --kinds-c=+plz --fields=+nie -o - /tmp/extern-c.c f function 3 /tmp/extern-c.c void f() {} $ cat /tmp/none-extern-c.c #ifdef X void f() {} #else void g() {} #endif $ u-ctags --output-format=xref --kinds-c=+plz --fields=+nie -o - /tmp/none-extern-c.c f function 2 /tmp/none-extern-c.c void f() {} g function 4 /tmp/none-extern-c.c void g() {} The function g() is missed if the code is surrounded by extern "C" { and }. This change uses a heuristic rule to skip the code in the C parser. In most of cases, the code is in #ifdef __cplusplus ~ #endif branch. So when the CPreProcessor parser detects #ifdef __cplusplus ~ #endif, with this change, the CPreProcessor parser doesn't pass the code inside __cplusplus branch to its client parser that requests to the CPreProcessor parser to do so. C parser requests it. C++ parser doesn't. Signed-off-by: Masatake YAMATO <[email protected]>
Though I still don't understand why. |
I found this is nothing to do with extern "C" { ... }.
|
I can add another testcase for thier behavior.
|
Seems that we should not call
|
I find the definition will not be parsed in the
#else
andextern "C"
.The sample code:
I use following command to parse:
Result is:
The
testMax2
andNB2
are not parsed, whiletestMax4
andNB4
are parsed.I think
extern "C"
will cause this error. Can you support this situation?The text was updated successfully, but these errors were encountered: