Bug 406842 - C++20 Modules
Summary: C++20 Modules
Status: CONFIRMED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (other bugs)
Version First Reported In: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords: junior-jobs
Depends on:
Blocks:
 
Reported: 2019-04-24 11:36 UTC by Lukas Kahnert
Modified: 2024-01-31 13:26 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lukas Kahnert 2019-04-24 11:36:45 UTC
Modules TS got merged into C++20 and it's already possible to use the new syntax with clang 8.0. In the docs, libclang should also provide an API for this:
https://clang.llvm.org/doxygen/group__CINDEX__MODULE.html


STEPS TO REPRODUCE
1. Write a "header" file(.cppm) with declarations.
2. Precompile the file with "clang++ -std=c++2a -fmodules-ts --precompile".
3. Write a source file inside KDevelop which imports the module.


OBSERVED RESULT
No syntax highlighting or code-completion of declarations imported from modules.


EXPECTED RESULT
Declarations imported from modules have syntax-highlighting and code completion.


SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Gentoo with kernel 5.0.7
KDE Plasma Version: 5.15.4
KDE Frameworks Version: 5.57.0
Qt Version: 5.12.2
Comment 1 Kevin Funk 2019-04-24 12:18:48 UTC
Hey,

are you maybe interested in diving into the KDevelop code base to fix this? Helping hands are needed.

Since the file extension is new, it might make sense to first have a look at the "ClangHelpers::isHeader" method in clanghelpers.cpp, and make sure .cppm is detected as "header file".

More information about contributing to KDevelop here:
  https://www.kdevelop.org/contribute-kdevelop
Comment 2 Milian Wolff 2019-04-24 12:47:05 UTC
thanks for the report! I'll try to find some time to look into this. Afaik the modules-ts implementation is still somewhat in flux, right?

anyhow, to simplify our life: can you attach a fully standalone cmake/makefile-based project that I can use to look into this?
Comment 3 Lukas Kahnert 2019-04-24 13:37:21 UTC
Modules TS syntax itself is finished AFAIK. clang recently also enabled the -fmodules-ts flag implicitly if -std=c++2a is used.

On clang 8.0 it's still unstable and segfaults in some use-cases, but with the C++20 release this situation will be better in the future.
Currently converting header files to the Modules TS syntax and additional compile flags works.

I try to make a small project and post the link here asap.

I would also provide some additional info how modules are compiled under clang. Sadly the docs talk mostly about clang-exclusive modules which differ from C++20:

Under clang c++ modules are source files(*.cppm), which can also provide declarations and in this case work like header files too.
The source file, which imports a module, needs the path to a module interface unit(*.pcm), which provides the required declarations for compilation.
A module interface unit is very similar to precompiled headers but with the difference that clang take only the declarations that are marked as 'export' and precompiles them as *.pcm file.
Comment 4 Lukas Kahnert 2019-04-25 07:58:48 UTC
Here a simple Project which uses clang for module compilation.

https://github.com/OpenProgger/CXXModule-Example
Comment 5 Justus Ranvier 2022-01-19 19:27:41 UTC
I hope that whenever module support gets added it does not preclude gcc support.

Currently kdevelop's reliance on clang for parsing means that if you turn on precompiled headers in your project and use gcc as a compiler then the parser stops working. (Bug 407444) .

Since modules are similar to precompiled headers in the sense that it's not expected to be compatible between compilers, it's possible that a naive implementation of modules in kdevelop will add another gcc incompatibility.
Comment 6 Richard Kellnberger 2024-01-31 13:26:58 UTC
As GCC now has module support and the feature is no longer experimental in CMake, I gave it a shot and with GCC not even a minimal example works.
Modules are not found (they cannot be I guess as KDevelop uses clang for its parsing and therefore requires its respective module files.)

Is there a plan/a way to handle this?

I would gladly help if support for modules with GCC is possible.