Skip to content

[modules][concepts] clang fails to correctly check constrained satisfaction when using modules #62589

@FabioFracassi

Description

@FabioFracassi

Consider the following (C++23) code:

auto str = std::string{"hello"};
auto s = std::basic_string_view{str};

this constructs a basic_string_view using CTAD and the C++23 range ctor. (In user code most people would probably use std::string_view{str}, but that is not the point here, I came across this when chasing the root cause for an issue in a formatter I wrote, and libc++ uses the above in its formatter implementation)

So far so good. This works as expected if I am using it in non module code. Now for the interesting part: if I try to import string/string_view/basic_string_view form a module

export module mystd;
export namespace std {
    using std::string;
    using std::string_view;
    using std::basic_string_view;
}

it stops working failing with error: constraints not satisfied.

I have been able to fix this by also explicitly exporting some -at least in my estimation- unrelated operator overloads (comparisons and +/-)

CE link with complete code: https://godbolt.org/z/qYchnbqKM. (Check with #define NO_WORKAROUND) to see the error.

leaving aside the issue that these are standard types and that the exported operators would be needed in a proper std module,
AFAIU it should not be necessary to explicitly export more than the types/names directly involved (i.e. string and basic_string_view)

tested on Clang/libc++ 16.0.x and trunk

Metadata

Metadata

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions