Initialisation de std :: initializer_list <std :: string_view>

Oct 30 2020

Le programme suivant

#include <initializer_list>
#include <string_view>

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

int main() {}

compile avec Clang actuel (12.0.0) mais pas avec GCC actuel (11.0.0 20201028). Avec GCC, il produit l'erreur

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

De [dcl.init.list / 5] et du fait que le constructeur string_view (char const *) est constexpr , je suppose que le comportement de Clang est juste ici.

Est-ce exact?

Réponses

1 xskxzr Nov 08 2020 at 08:54

Oui vous avez raison. C'est un bogue GCC .