The following code compiles on gcc, but fails on msvc and clang:
template <unsigned int N>
struct array {
constexpr auto size() const -> unsigned int {
return N;
}
};
constexpr auto foo(array<5> const& arr) {
return array<arr.size()>{}.size();
}
constexpr auto bar(array<5> arr) {
return array<arr.size()>{}.size();
}
int main()
{
array<5> arr {};
static_assert(arr.size() == 5);
static_assert(foo(arr) == 5);
static_assert(bar(arr) == 5);
}
https://godbolt.org/z/q1xajW1Gq
However, if size is made static, msvc also compiles:
https://godbolt.org/z/Tfqe5E9z8
The problem seems to be with arr being passed by reference, as passing by value also get accepted.