[Bug c++/124057] GCC still rejects C++26 constexpr std::span using std::initializer_list
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Feb 12 09:24:57 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124057
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
GCC is correct. That constructor is only valid for temporaries.
#include <span>
#include<initializer_list>
consteval int f(std::span<const int> s) { return s.size(); }
int main() {
constexpr int n = f({0,0}); // accepted as of c++26 p2447
static_assert(n == 2);
}
Your example forms a dangling pointer.
More information about the Gcc-bugs
mailing list