Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 534
plexando Avatar asked Oct 30 '20 11:10

plexando


1 Answers

Yes, you are correct. It is a GCC bug.

like image 51
xskxzr Avatar answered Sep 27 '22 21:09

xskxzr