-
Notifications
You must be signed in to change notification settings - Fork 11.7k
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
[clang++-19][regression] "error: type constraint differs in template redeclaration" #110231
Comments
A repro can be found here: https://godbolt.org/z/6brEd3de6. It also fails on "clang (trunk)," but it works fine on the other compilers mentioned. |
@llvm/issue-subscribers-clang-frontend Author: Mateusz Pusz (mpusz)
I get the following error while compiling on clang-19:
Here are the offending declarations:
The same code works fine on clang-17, clang-18, gcc-13, and gcc-14. |
I came to open an issue exactly about this with llvm-19.1.0 via homebrew on Apple M1 Pro CPU. |
Looks like this started in clang-19: https://godbolt.org/z/oxPf3oWjM I would like a reduction to understand what is going on better though. |
Confirmed on 19 and trunk. Note several declarations between struct array {
int __elems_[4] = {1, 2, 3, 4};
};
template < typename, template < typename > typename >
int is_specialization_of;
template < typename, template < auto... > typename >
constexpr bool is_specialization_of_v = 0;
template < auto... Params, template < auto... > typename Type >
constexpr bool is_specialization_of_v< Type< Params... >, Type > = 1;
constexpr auto get_first_of(int n) {
auto g = [&]{};
int __elems_[4] = {1, 2, 3, 4};
int* first = __elems_;
for (;;++first)
if (n % (*first))
return *first;
return 0;
}
consteval int find_first_factor(int n) {
constexpr auto basis = array{};
auto k = get_first_of(n);
return k;
}
template < typename T >
concept PowerVBase = true;
template < PowerVBase auto, int >
struct power_v {
static constexpr auto base = 0;
};
template < typename T >
concept MagnitudeSpec = is_specialization_of_v< T, power_v >;
template < MagnitudeSpec auto... >
struct magnitude;
template < typename T >
concept Magnitude = is_specialization_of_v< T, magnitude >;
template < auto V >
consteval auto power_v_or_T() {
return power_v< V, 0 >{};
}
template < typename >
struct magnitude_base {};
template < MagnitudeSpec auto... Ms >
struct magnitude : magnitude_base< magnitude< Ms... > > {
template < Magnitude M >
friend consteval auto operator*(magnitude m1, M) {
return m1;
}
friend auto operator/(magnitude, auto r) {
return pow(r);
}
friend auto pow(magnitude) {
return magnitude< power_v_or_T< Ms >()... >{};
}
};
template < int N >
struct prime_factorization {
static constexpr int first_base = find_first_factor(N);
static constexpr int remainder = N / first_base;
static constexpr auto value = magnitude< power_v_or_T< first_base >() >{} * prime_factorization< remainder >::value;
};
template <>
struct prime_factorization< 0 > {
static magnitude<> value;
};
template < int N >
auto prime_factorization_v = prime_factorization< N >::value;
template < auto, auto >
concept NestedQuantityKindSpecOf = true;
template < typename T, auto >
concept QuantitySpecOf = NestedQuantityKindSpecOf< 0, T{} >;
template < Magnitude auto >
struct scaled_unit {};
template < typename T >
concept Reference = true;
template < typename T, auto >
concept PointOriginFor = true;
struct unit_interface {};
template < typename M >
consteval auto operator*(M, unit_interface) -> scaled_unit< M{} > {
return scaled_unit< M{} >{};
}
template < auto >
struct named_unit;
template < auto U >
requires(true)
struct named_unit< U > {};
template < Reference auto R, PointOriginFor< R > auto >
struct quantity_point;
auto mag_ratio = prime_factorization_v< 0 > / prime_factorization_v< 1000 >;
template class named_unit< mag_ratio * unit_interface{} >;
template < Reference auto R, PointOriginFor< R > auto >
struct quantity_point; Clang 20 output:
|
CC @mizvekov because I saw several TTPs are at play (where the situation could be horrible) |
Somewhat surprisingly, when I locally ran Clang 19.1 binary that CE uses against the reduction, I got a crash:
|
When I feed a local debug build of trunk with the reduction, I consistently get the following diagnostics:
|
On godbolt using It |
I guess it runs out of stack like it did for me several comments above |
Bisected to #92425 |
Also see bc62fb9 which introduced CC @zygoloid who implemented that patch |
…ck argument This fixes a regression introduced in #96023, reported in #110231 (comment)
That's a separate regression introduced by a recent commit, should be fixed by #110963 |
I get the following error while compiling on clang-19:
Here are the offending declarations:
The same code works fine on clang-17, clang-18, gcc-13, and gcc-14.
The text was updated successfully, but these errors were encountered: