-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Clang fails to compile consteval because of conflicting rule for variable arrays (?) #105796
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
Comments
At this time you can write Slightly reduced example (Godbolt link): #include <cstddef>
#include <type_traits>
template <std::size_t N>
struct record {
consteval record(std::integral_constant<std::size_t, N>) {}
template <std::size_t N2>
consteval std::size_t test_with(const record<N2> other) const {
constexpr auto len = size() + other.size() + 1; // HERE
return len;
}
consteval std::size_t size() const { return N - 1; }
};
template <record Foo>
consteval auto test_two_records() {
return Foo.test_with(Foo);
}
int main() {
constexpr auto n = test_two_records<std::integral_constant<std::size_t, 42>{}>();
} I believe this is P2280R4 which is tracked in #63139 and will be fixed by #95474. |
@frederick-vs-ja Thank you, I already know how to fix. I just reported obvious bug in Clang. |
@llvm/issue-subscribers-clang-frontend Author: Коренберг Марк (socketpair)
https://godbolt.org/z/dKE6sa4PW
#include <algorithm>
#include <array>
template <std::size_t N>
struct CompTimeStr {
std::array<char, N> store;
consteval CompTimeStr(const char (&str)[N]) {
std::copy_n(str, store.size(), store.data());
}
template <std::size_t N2>
consteval CompTimeStr<N + N2 - 1> operator+(
const CompTimeStr<N2> str) const {
char newchar[size() + str.size() + 1];
std::copy_n(data(), size(), newchar);
std::copy_n(str.data(), str.size() + 1, newchar + size());
return newchar;
}
consteval std::size_t size() const { return store.size() - 1; }
consteval const char* data() const { return store.data(); }
};
template <CompTimeStr str>
consteval auto addBar() {
return str + str;
}
int main() {
constexpr CompTimeStr str = addBar<"foo">();
return str.size();
} |
Related: #102970 |
Reduced some more: https://godbolt.org/z/x7P9TjYce template <typename, unsigned>
struct A{};
template <unsigned N>
struct record {
consteval record(A<unsigned, N>) {}
consteval unsigned test_with() const {
constexpr auto len = size() + 1;
return len;
}
consteval unsigned size() const { return N - 1; }
};
template <record F>
consteval auto test_two_records() {
return F.test_with();
}
void g() {
constexpr auto n = test_two_records<A<unsigned, 42>{}>();
}
|
I am not sure this is totally unknown refs and ptrs. It looks like we are not seeing up |
Based on this, I think this is an unrelated bug: https://godbolt.org/z/nMh8Mebqo |
Uh oh!
There was an error while loading. Please reload this page.
https://godbolt.org/z/dKE6sa4PW
The text was updated successfully, but these errors were encountered: