gcc 8.0.0和clang 5.0.0不同意这个程序的行为:的转发参考,并扣除正常参考部分订购指南
#include <iostream>
template <typename T>
struct A {
A(const T&) { std::cout << __PRETTY_FUNCTION__ << '\n'; }
A(T&&) { std::cout << __PRETTY_FUNCTION__ << '\n'; }
};
template <typename U> A(U&&) -> A<double>;
int main() {
int i = 0;
const int ci = 0;
A a1(0); // both say A<double>
A a2(i); // both say A<double>
A a3(ci); // gcc says A<int>, clang says A<double>
}
GCC的行为没有任何意义,我 - 如果const T&
超载最好的U&&
过载为左值const int
,为什么不是T&&
过载首选到U&&
过载对于右值int
?铿锵声对我来说更有意义(没有一个功能比其他功能更专业,所以演绎指南获胜)。
谁是对的?
我会对此进行一次刺探。扣除是针对一个右值(参考)。 'ci'是'const'的左值,碰巧有一个构造函数将'const'的引用作为参数。 –
请原谅我缺乏的知识,但是这个' - >'语法是如何调用的? – HolyBlackCat