Playing with rvalue- and forwarding references to C-style arrays, I stumbled upon weird behaviour. At first I thought it was due to my lack of understanding how C-style arrays bind to &&
references, but now, after reading this related question, it seems to be an MS C++ compiler bug.
The code:
#include <boost/type_index.hpp>
#include <iostream>
#include <utility>
template<typename T>
void foo(T&&) {
std::cout << boost::typeindex::type_id_with_cvr<T>() << '\n';
}
void bar(int(&)[2]) {
std::cout << "int(&)[2]\n";
}
void bar(int(&&)[2]) {
std::cout << "int(&&)[2]\n";
}
int main() {
int arr[2];
// MSVS 2018 / gcc 7.1.0 & clang 5.0.0
foo(arr); // Outputs: int(&)[2] / int(&)[2]
foo(std::move(arr)); // Outputs: int(&)[2] / int[2]
bar(arr); // Outputs: int(&)[2] / int(&)[2]
bar(std::move(arr)); // Outputs: int(&)[2] / int(&&)[2]
return 0;
}
Are gcc/clang right here? Can this be classified as an MS compiler bug?
Aucun commentaire:
Enregistrer un commentaire