看到一道题说以下s的引用非法,但在vs2012上试验后却可以准确运行,求解释

#include
#include
#include

using namespace std;

string foo()
{
//string t = "asfds";
return "asfds";
//return t;
}

void bar(string &s)
{
cout << s << endl;
}

int main()
{
bar(foo());
system("pause");
return 0;
}

为什么可以运行,foo函数返回的临时变量不是会被释放掉的吗,bar函数的参数s是哪个变量的引用

"asfds"存放在只读常量区,而不是栈区,所以返回后,此内存还没有释放,如果改成char buff[]= "zaizhanqu",然后返回,因为buff在栈区,值会被回收,而buff只是一个符号地址,没有内存空间,所以会存在潜在的危险。