Initialization of std::initializer_list<std::string_view>

Viewed 254

The following program

#include <initializer_list>
#include <string_view>

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

int main() {}

compiles with current Clang (12.0.0) but not with current GCC (11.0.0 20201028). With GCC it produces the error

prog.cc:4:67: error: modification of '<temporary>' is not a constant expression
    4 | inline constexpr std::initializer_list<std::string_view> s = { "" };
      |                                                                    ^

From [dcl.init.list/5] and the fact that the string_view(char const*) constructor is constexpr, I assume that Clang's behavior is right here.

Is that correct?

1 Answers
Related