What's the case if clang module and c++20 module are enabled at the same time?

Hi,

Recently I am developing C++20 semantics in clang. Then I met an interesting bug in
compare-modules-cxx2a.cpp (llvm-project/compare-modules-cxx2a.cpp at main · llvm/llvm-project · GitHub).

The key point here is that the test uses -std=c++2a and -fmodules both. So my codes which is intended to work for C++20 module now tests for clang module. So here is the reason for the bug.

Beyond my personal work, it is weired for me that we could use clang module and c++20 module at the same time. (I know the implementation of c++20 is based on clang module).
So I want to ask: do we have considered the case that we use clang module and c++20 module together? Is it neceesary? And what’s the status after the user enable c++20 module and clang module?

For example, when we enter “clang -std=c++20 -fprebuilt-module-path=%t %s -c” to the command line, both getLangOpts().CPlusPlusModules and getLangOpts().Modules would evaluate to true, which is really weired.
Is it intentional? Or is it a bug simply? Now I couldn’t avoid the bug by if (getLangOpts().CPlusPlusModules && !getLangOpts().Modules).

I CCed people who looks like interested and related. Remind me if you feel uncomfortable.

Thanks,
Chuanqi

Hi,

   Recently I am developing C++20 semantics in clang. Then I met an interesting bug in
compare-modules-cxx2a.cpp (llvm-project/compare-modules-cxx2a.cpp at main · llvm/llvm-project · GitHub).

    The key point here is that the test uses `-std=c++2a` and `-fmodules` both. So my codes which is intended to work for C++20 module now tests for clang module. So here is the reason for the bug.

    Beyond my personal work, it is weired for me that we could use clang module and c++20 module at the same time. (I know the implementation of c++20 is based on clang module).
So I want to ask: do we have considered the case that we use clang module and c++20 module together? Is it neceesary? And what's the status after the user enable c++20 module and clang module?

    For example, when we enter "clang -std=c++20 -fprebuilt-module-path=%t %s -c" to the command line, both `getLangOpts().CPlusPlusModules` and `getLangOpts().Modules` would evaluate to true, which is really weired.
Is it intentional? Or is it a bug simply? Now I couldn't avoid the bug by `if (getLangOpts().CPlusPlusModules && !getLangOpts().Modules)`.

Personally, I think this was an oversight. It seems to me that trying
to be in both modules modes at the same time is not something we want
to support, so I'd be in favor of treating these as mutually exclusive
options and the user gets an error if they try.

~Aaron

Hi

Hi

>> Personally, I think this was an oversight. It seems to me that trying
>> to be in both modules modes at the same time is not something we want
>> to support, so I'd be in favor of treating these as mutually exclusive
>> options and the user gets an error if they try.
>>
>> ~Aaron
---

   I think so that we could avoid to support two modes at the same time. Another problem is that what's the behavior if user enabled '-std=c++20' and '-fmodules'.
I think an error may not be friendly enough since people may want to use other feature in C++20 and clang module.

Personally, I don't consider that to be a valid use case. If the user
wants C++20, they get modules because that's what it means to compile
against C++20

I wonder if it would be better when "-std=c++20"
and "-fmodules" occur at the same time, the compiler should emit a warning and disable c++20 modules by settting `CPlusPlusModules` to false. What's your opinion?

I think I'd feel more comfortable if the user had to explicitly opt
*out* of the C++20 feature. e.g., `clang -std=c++20 -fno-cxx-modules
-fmodules` (though if we went this route, it might be a kindness to
consider renaming -fmodules to -fclang-modules). We have a similar
relationship with exceptions -- you get them by default, but you can
opt out of them if you need to (or opt into other exception models).

~Aaron

Hi Aaron,

Your suggestion makes sense. I have posted a issue here: 52413 – [C++20] [Module] Emit an error if user enables both c++20 module and clang module.
It would be great if someone who is more familiar with clang driver would love to fix it.
If others are busy, I would try to fix it. I guess it might not be so hard to implement?

Thanks,
Chuanqi