Ich habe folgendes Testprogramm nicht bindend:Temporäre const Array rvalue Referenz
#include <iostream>
#include <type_traits>
#include <utility>
template<typename Ty, std::size_t N>
void foo(Ty (&&)[N])
{
std::cout << "Ty (&&)[" << N << "]\t" << std::is_const<Ty>::value << '\n';
}
template<typename Ty, std::size_t N>
void foo(Ty (&)[N])
{
std::cout << "Ty (&)[" << N << "]\t" << std::is_const<Ty>::value << '\n';
}
template<typename Ty>
using id = Ty;
int main()
{
std::cout.setf(std::cout.boolalpha);
foo(id<int[]>{1, 2, 3, 4, 5});
foo(id<int const[]>{1, 2, 3, 4, 5}); // <-- HERE.
int xs[]{1, 2, 3, 4, 5};
foo(xs);
int const ys[]{1, 2, 3, 4, 5};
foo(ys);
foo(std::move(xs));
foo(std::move(ys));
}
Ich würde erwarten, dass die Linie mit einem Pfeil markiert würde gerade über die R-Wert Überlastung wie der nicht-const Anruf nennen, aber es tut es nicht.
Ist das nur ein Fehler in GCC oder gibt es etwas im Standard, das die Lvalue-Überladung verursacht?
Interessant, Clang wird das richtig und ruft die Rvalue-Überladung auf. – Xeo
Gute Frage: Mein naives Verständnis des Standards stimmt mit Ihrem überein. [Live] (http://ideone.com/ErHuYO), wenn Sie die Ausgabe sehen möchten. – Yakk
Etwas lustiges geht hier: http://ideone.com/ptTJ8i - mein 'const int' temporäres wird wie ein' int && 'behandelt, nicht ein' const int && '. – Yakk