Answer 1 of the post How to declare array with auto works fine:
template<typename T> using unsized_raw_array = T[];
auto &&z = unsized_raw_array<int>{1, 2, 3};
Trying out the same but without the double ampersand (&&
) results in different behavior of clang and gcc:
template<typename T> using unsized_raw_array = T[];
auto z = unsized_raw_array<int>{1, 2, 3};
I expected this to be an error because it is an rvalue (universal/forwarding/temporary-object) reference and the double ampersand is missing (&&
). And that is what happens with gcc 6.3.0:
error: taking address of temporary array
However, clang 3.9.1 compiles and executes it successfully, allowing printing the values of the array in the next statements. I only get this warning (in some scenarios I don't even get the warning):
warning: pointer is initialized by a temporary array, which will be destroyed at the end of the full-expression [-Waddress-of-array-temporary]
Which compiler is correct?