关于C++函数返回临时对象

下面的代码:

#include <string>
#include <iostream>

using namespace std;  
string Func()
{
    return string(); 
}

int main()
{
    Func() = "foo"; 
    return 0;

}

为什么在g++和MSVC上都能编译通过?Func返回的临时对象不是右值吗?右值为什么能够被赋值呢?

不同的编译器对标准支持不一样。早期编译器不行,需要分开
string s = Func();
s = "foo";