Skip to content

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

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

Open
ilya-biryukov opened this issue Sep 13, 2023 · 4 comments
Labels
c++20 clang:modules C++20 modules and Clang Header Modules

Comments

@ilya-biryukov
Copy link
Contributor

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.
@github-actions github-actions bot added clang Clang issues not falling into any other category new issue labels Sep 13, 2023
@ilya-biryukov ilya-biryukov added c++20 clang:modules C++20 modules and Clang Header Modules labels Sep 13, 2023
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2023

@llvm/issue-subscribers-clang-modules

Run a compiler on this code: ```cpp // --- 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
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:

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
Copy link
Member

llvmbot commented Sep 13, 2023

@llvm/issue-subscribers-c-20

Run a compiler on this code: ```cpp // --- 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
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:

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.

@ilya-biryukov
Copy link
Contributor Author

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.

@Endilll Endilll removed clang Clang issues not falling into any other category new issue labels Sep 15, 2023
@ChuanqiXu9 ChuanqiXu9 changed the title Clang incorrectly complains about default argument not being reachable Clang incorrectly complains about default template argument not being reachable Sep 18, 2023
@cor3ntin
Copy link
Contributor

cor3ntin commented Aug 9, 2024

@ilya-biryukov can we close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:modules C++20 modules and Clang Header Modules
Projects
Status: Done
Development

No branches or pull requests

4 participants