Bug 402066

Summary: Fail at semantic analysis for includes within extern "C"
Product: [Applications] kdevelop Reporter: Aleix Pol <aleixpol>
Component: Language Support: CPP (Clang-based)Assignee: kdevelop-bugs-null
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: git master   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: patch that adds a test case

Description Aleix Pol 2018-12-12 17:34:46 UTC
Created attachment 116881 [details]
patch that adds a test case

SUMMARY
There's a test case attached with a positive and a negative case.

Given a foo.h such as:
"int foo();"

And a main.cpp such as:
"
extern "C" {
#include "foo.h"
}

int main() { return foo(); }
"

OBSERVED RESULT
Project compiles but foo uses or declarations don't get highlighted.
If extern "C" is removed from main.cpp it all works.

EXPECTED RESULT
It should work even with extern "C"

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: master
Running clang 7.0, but I've had this issue for a while.

ADDITIONAL INFORMATION
Comment 1 Milian Wolff 2020-02-06 19:25:05 UTC
Git commit a7f7c9ac6b8fc9254d7efe17adde7d95b613bb1c by Milian Wolff.
Committed on 06/02/2020 at 19:23.
Pushed by mwolff into branch 'master'.

kdev-clang: don't skip unexposed declarations from different files

clang-c doesn't expose the 'extern "C"' linkage declaration. In some
cases, projects put #include statements within such linkage
statements. We used to fail to create declarations for them, and thus
also failed to build proper uses for any declaration.

M  +9    -4    plugins/clang/duchain/builder.cpp
C  +8    -0    plugins/clang/tests/files/extern_c.cpp [from: plugins/clang/tests/files/includes.cpp - 060% similarity]
M  +6    -0    plugins/clang/tests/files/includes.cpp
A  +2    -0    plugins/clang/tests/files/includes/asdf.h     [License: Trivial file]
M  +31   -0    plugins/clang/tests/test_duchain.cpp
M  +1    -0    plugins/clang/tests/test_duchain.h

https://invent.kde.org/kde/kdevelop/commit/a7f7c9ac6b8fc9254d7efe17adde7d95b613bb1c
Comment 2 Milian Wolff 2020-02-14 10:04:25 UTC
Git commit 11cdf99776e4ac039a0351404f76ab697f862ff2 by Milian Wolff.
Committed on 14/02/2020 at 10:03.
Pushed by mwolff into branch '5.5'.

kdev-clang: don't skip unexposed declarations from different files

clang-c doesn't expose the 'extern "C"' linkage declaration. In some
cases, projects put #include statements within such linkage
statements. We used to fail to create declarations for them, and thus
also failed to build proper uses for any declaration.
(cherry picked from commit a7f7c9ac6b8fc9254d7efe17adde7d95b613bb1c)

M  +9    -4    plugins/clang/duchain/builder.cpp
C  +8    -0    plugins/clang/tests/files/extern_c.cpp [from: plugins/clang/tests/files/includes.cpp - 060% similarity]
M  +6    -0    plugins/clang/tests/files/includes.cpp
A  +2    -0    plugins/clang/tests/files/includes/asdf.h     [License: Trivial file]
M  +31   -0    plugins/clang/tests/test_duchain.cpp
M  +1    -0    plugins/clang/tests/test_duchain.h

https://invent.kde.org/kde/kdevelop/commit/11cdf99776e4ac039a0351404f76ab697f862ff2