【发布时间】:2017-07-28 06:54:24
【问题描述】:
考虑以下代码:
constexpr auto f()
{
auto str = "Hello World!";
return str;
}
int main(int argc, char* argv[])
{
static constexpr auto str = f();
std::cout << str << std::endl;
return 0;
}
我的编译器不显示任何警告是否正常?它是定义的行为吗?我能保证程序会显示"Hello World!"吗?我希望"Hello World!" 不会超出函数的范围......
【问题讨论】:
标签: c++ c++14 constexpr c-strings string-literals