llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.53k stars 11.79k forks source link

Clang incorrectly complains about default template argument not being reachable #66255

Open ilya-biryukov opened 1 year ago

ilya-biryukov commented 1 year ago

Run a compiler on this code:

// --- foo.cppm
export module foo;

export struct partial {};
export template <class T, class Cat = partial> concept is_comparable = true;

// --- bar.cppm
export module bar;

import foo;
template <class T>
void func() requires is_comparable<T> {}

The exact commands are:

$ clang++ -std=c++20 --precompile foo.cppm
$ clang++ -std=c++20 --precompile bar.cppm -fmodule-file=foo.pcm

Expected results: code compiles with no errors. Actual: Clang produces the following error when compiling the module bar:

bar.cppm:6:22: error: default argument of 'is_comparable' must be imported from module 'foo' before it is required
void func() requires is_comparable<T> {}
                     ^
foo.cppm:5:39: note: default argument declared here is not reachable
export template <class T, class Cat = partial> concept is_comparable = true;
                                      ^
1 error generated.
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-modules

Run a compiler on this code: ```cpp // --- foo.cppm export module foo; export struct partial {}; export template concept is_comparable = true; // --- bar.cppm export module bar; import foo; template void func() requires is_comparable {} ``` The exact commands are: ```sh $ clang++ -std=c++20 --precompile foo.cppm $ clang++ -std=c++20 --precompile bar.cppm -fmodule-file=foo.pcm ``` Expected results: code compiles with no errors. Actual: Clang produces the following error when compiling the module `bar`: ```sh bar.cppm:6:22: error: default argument of 'is_comparable' must be imported from module 'foo' before it is required void func() requires is_comparable {} ^ foo.cppm:5:39: note: default argument declared here is not reachable export template concept is_comparable = true; ^ 1 error generated. ```
llvmbot commented 1 year ago

@llvm/issue-subscribers-c-20

Run a compiler on this code: ```cpp // --- foo.cppm export module foo; export struct partial {}; export template concept is_comparable = true; // --- bar.cppm export module bar; import foo; template void func() requires is_comparable {} ``` The exact commands are: ```sh $ clang++ -std=c++20 --precompile foo.cppm $ clang++ -std=c++20 --precompile bar.cppm -fmodule-file=foo.pcm ``` Expected results: code compiles with no errors. Actual: Clang produces the following error when compiling the module `bar`: ```sh bar.cppm:6:22: error: default argument of 'is_comparable' must be imported from module 'foo' before it is required void func() requires is_comparable {} ^ foo.cppm:5:39: note: default argument declared here is not reachable export template concept is_comparable = true; ^ 1 error generated. ```
ilya-biryukov commented 1 year ago

I believe this particular bug is only applicable to older Clang versions (definitely present in clang 14). I could not actually reproduce at head.

But we are seeing a similar issue with a generated module map we're using for libc++, I will keep this issue open for a few days while I'm trying to get a reduced reproducer.

cor3ntin commented 2 months ago

@ilya-biryukov can we close?