Clang编译器生成警告编译此代码片段,我无法弄清楚原因.
const int* Get() {
static const int ARRAY[4] = {1, 2, 3, 4};
return &ARRAY[0];
}
const int& Test() {
const auto& p = Get();
return (*p);
}
warning: returning reference to local temporary object [-Wreturn-stack-address]
return (*p);
Run Code Online (Sandbox Code Playgroud)
GCC没有显示此代码的警告.我可以修复这样的片段:const auto p = Get();
但我想知道是否有一些临时对象,问题更深层次