gpt4 book ai didi

c++ - std::initializer_list 的初始化

转载 作者:行者123 更新时间:2023-12-03 06:50:06 24 4
gpt4 key购买 nike

下面的程序

#include <initializer_list>
#include <string_view>

inline constexpr std::initializer_list<std::string_view> s = { "" };

int main() {}
使用当前的 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 = { "" };
| ^
来自 [dcl.init.list/5]并且 string_view(char const*) 构造函数是 constexpr 的事实,我假设 Clang 的行为就在这里。
那是对的吗?

最佳答案

是的,你是对的。这是一个 GCC bug .

关于c++ - std::initializer_list<std::string_view> 的初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64607860/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com