ple*_*ndo 7 c++ constructor language-lawyer c++17
下面的程序
#include <initializer_list>
#include <string_view>
inline constexpr std::initializer_list<std::string_view> s = { "" };
int main() {}
Run Code Online (Sandbox Code Playgroud)
使用当前的 Clang (12.0.0) 编译,但不使用当前的 GCC (11.0.0 20201028) 编译。使用 GCC 会产生错误
prog.cc:4:67: error: modification of '<temporary>' is not a constant expression
4 | inline constexpr std::initializer_list<std::string_view> s = { "" };
| ^
Run Code Online (Sandbox Code Playgroud)
来自[dcl.init.list/5]以及string_view(char const*)构造函数是constexpr的事实,我假设 Clang 的行为就在这里。
那是对的吗?
| 归档时间: |
|
| 查看次数: |
147 次 |
| 最近记录: |