临时绑定到左值引用

Nav*_*K N 9 c++ compiler-construction rvalue lvalue

我有以下代码

string three()
{
    return "three";
}

void mutate(string& ref)
{
}

int main()
{
    mutate(three()); 
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

你可以看到我正在传递three()mutate方法.这段代码汇编得很好.我的理解是,临时工具不能分配给非const引用.如果是,该程序如何编译?

有什么想法吗?

编辑:

编译器尝试过:VS 2008和VS2010 Beta

Nav*_*een 8

它用于在VC6编译器中编译,所以我猜维护后向兼容性VS2008正在支持这种非标准的扩展.尝试使用/ Za(禁用语言扩展)标志,然后你应该得到一个错误.

  • 使用警告级别作为四是我使用的更好的选项 (5认同)