【问题标题】:Initialization of std::initializer_list<std::string_view>std::initializer_list<std::string_view> 的初始化
【发布时间】:2020-10-30 11:52:28
【问题描述】:

下面的程序

#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 的行为就在这里。

对吗?

【问题讨论】:

  • 我没有仔细阅读this 的帖子,但我认为它可以让您对正在发生的事情有所了解。

标签: c++ constructor c++17 language-lawyer


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2016-12-22
    • 1970-01-01
    • 2018-01-13
    • 2019-04-16
    • 2015-09-04
    • 1970-01-01
    • 2013-03-22
    • 1970-01-01
    相关资源
    最近更新 更多