非类右值总是具有cv非限定类型 [英] non-class rvalues always have cv-unqualified types

查看:145
本文介绍了非类右值总是具有cv非限定类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

§3.10第9节说非类别右值总是具有cv非限定类型。这使我很奇怪...

§3.10 section 9 says "non-class rvalues always have cv-unqualified types". That made me wonder...

int foo()
{
    return 5;
}

const int bar()
{
    return 5;
}

void pass_int(int&& i)
{
    std::cout << "rvalue\n";
}

void pass_int(const int&& i)
{
    std::cout << "const rvalue\n";
}

int main()
{
    pass_int(foo()); // prints "rvalue"
    pass_int(bar()); // prints "const rvalue"
}

根据标准,事物作为非类型的const值,但 bar()更喜欢绑定到 const int&&& 。这是一个编译器错误吗?

According to the standard, there is no such thing as a const rvalue for non-class types, yet bar() prefers to bind to const int&&. Is this a compiler bug?

编辑:显然,这个也是一个常数:)

Apparently, this is also a const rvalue :)

编辑:这个问题似乎在g ++ 4.5.0中修复,两行都打印rvalue。

This issue seems to be fixed in g++ 4.5.0, both lines print "rvalue" now.

推荐答案

委员会似乎已经意识到标准的这一部分有一个问题。 CWG问题690 介绍了与完全相同的部分有些类似的问题的标准(在2009年9月的补充说明中)。我估计很快就会为这部分标准起草新的语言。

The committee already seems to be aware that there's a problem in this part of the standard. CWG issue 690 talks about a somewhat similar problem with exactly the same part of the standard (in the "additional note" from September, 2009). I'd guess new language will be drafted for that part of the standard soon.

编辑:我刚刚提交了一个关于comp.std.c ++的文章,注意到问题和建议新的措辞相关的标准。不幸的是,作为一个温和的新闻组,几乎每个人都可能已经忘记了这个问题,当它通过批准队列在那里。

I've just submitted a post on comp.std.c++, noting the problem and suggesting new wording for the relevant piece of the standard. Unfortunately, being a moderated newsgroup, nearly everybody will probably have forgotten this question by the time it makes it through the approval queue there.

这篇关于非类右值总是具有cv非限定类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆