-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Arrays of variable templates cannot deduce their lengths from pack expansion in the initializer #79750
Comments
Curiously, |
@llvm/issue-subscribers-clang-frontend Author: mq白 (Mq-b)
```cpp
#include <iostream>
#include <type_traits>
template<std::size_t...values> int main() {
1
msvc considers
|
You're right, clang and gcc behave differently here, clang can If it is gcc, it is a compilation error. #include <iostream>
#include <type_traits>
template<std::size_t...values>
constexpr std::size_t array[]{ values... };
int main() {
std::cout<<sizeof(array<1,2,3,4,5>);
} |
This does look like a bug but not 💯 sure |
I found this case, originally as a class static variable, but reduced to enum class Values { A, B, C };
template<typename E>
inline constexpr Values values[] = {Values::A, Values::B, Values::C};
constexpr auto r = values<Values>[0] == Values::A; Fails with
But enum class Values { A, B, C };
inline constexpr Values values[] = {Values::A, Values::B, Values::C};
constexpr auto r = values[0] == Values::A; works. Both work in msvc/gcc |
Output:
Both gcc and clang have this result, but this is obviously not true, msvc outputs 0.
gcc and clang consider
array<1, 2, 3, 4, 5>
to be the same type asconst std::size_t[]
.msvc will only output 1 when faced with the following code.
msvc considers
array<1, 2, 3, 4, 5>
andconst std::size_t[5]
to be of the same type.The text was updated successfully, but these errors were encountered: