empty(const _Tp (&)[_Nm]) noexcept
{ return false; }
+#if __glibcxx_initializer_list < 202511L
/**
* @brief Return whether an initializer_list is empty.
* @param __il Initializer list.
constexpr bool
empty(initializer_list<_Tp> __il) noexcept
{ return __il.size() == 0;}
+#endif
/**
* @brief Return the data pointer of a container.
data(_Tp (&__array)[_Nm]) noexcept
{ return __array; }
+#if __glibcxx_initializer_list < 202511L
/**
* @brief Return the data pointer of an initializer list.
* @param __il Initializer list.
constexpr const _Tp*
data(initializer_list<_Tp> __il) noexcept
{ return __il.begin(); }
+#endif
#endif // __glibcxx_nonmember_container_access
#ifdef __glibcxx_ssize // C++ >= 20
};
};
+ftms = {
+ name = initializer_list;
+ values = {
+ v = 202511;
+ cxxmin = 26;
+ };
+};
+
// Standard test specifications.
stds[97] = ">= 199711L";
stds[03] = ">= 199711L";
#endif /* !defined(__cpp_lib_is_structural) */
#undef __glibcxx_want_is_structural
+#if !defined(__cpp_lib_initializer_list)
+# if (__cplusplus > 202302L)
+# define __glibcxx_initializer_list 202511L
+# if defined(__glibcxx_want_all) || defined(__glibcxx_want_initializer_list)
+# define __cpp_lib_initializer_list 202511L
+# endif
+# endif
+#endif /* !defined(__cpp_lib_initializer_list) */
+#undef __glibcxx_want_initializer_list
+
#undef __glibcxx_want_all
#include <bits/c++config.h>
+#define __glibcxx_want_initializer_list
+#include <bits/version.h>
+
namespace std _GLIBCXX_VISIBILITY(default)
{
/// initializer_list
// One past the last element.
constexpr const_iterator
end() const noexcept { return begin() + size(); }
+
+#if __glibcxx_initializer_list >= 202511L
+ constexpr bool
+ empty() const noexcept { return _M_len == 0; }
+
+ constexpr const value_type*
+ data() const noexcept { return _M_array; }
+#endif
};
+#if __glibcxx_initializer_list < 202511L
/**
* @brief Return an iterator pointing to the first element of
* the initializer_list.
constexpr const _Tp*
end(initializer_list<_Tp> __ils) noexcept
{ return __ils.end(); }
+#endif // __glibcxx_initializer_list < 202511L
}
#endif // C++11
--- /dev/null
+// { dg-do compile { target c++26 } }
+
+#include <initializer_list>
+#include <iterator>
+
+#ifndef __cpp_lib_initializer_list
+# error "Feature-test macro for text_encoding missing in <initializer_list>"
+#elif __cpp_lib_initializer_list != 202511L
+# error "Feature-test macro for text_encoding has wrong value in <initializer_list>"
+#endif
+
+void
+test02()
+{
+ static constexpr std::initializer_list<int> il{1};
+ static_assert( il.data() == il.begin() );
+ static_assert( il.empty() == false );
+ static_assert( noexcept(il.data()) );
+ static_assert( noexcept(il.empty()) );
+}
+
// 18.9.3 Initializer list range access [support.initlist.range]
#include <initializer_list>
+#if __cpp_lib_initializer_list >= 202511L
+# include <iterator>
+#endif
void
test01()
-{
- std::begin({1, 2, 3});
- std::end({1, 2, 3});
-}
-
-void
-test02()
{
static constexpr std::initializer_list<int> il{1};
static_assert( std::begin(il) == il.begin() );
--- /dev/null
+// { dg-do compile { target c++14 } }
+
+#include <initializer_list>
+#include <iterator>
+
+void
+test01()
+{
+ static constexpr std::initializer_list<int> il{1, 2};
+ static_assert( std::cbegin(il) == il.begin() );
+ static_assert( std::cend(il) == il.end() );
+#if __cplusplus >= 201703L
+ static_assert( std::rbegin(il).base() == il.end() );
+ static_assert( std::rend(il).base() == il.begin() );
+ static_assert( std::rbegin(il).base() == il.end() );
+ static_assert( std::rend(il).base() == il.begin() );
+#endif
+ static_assert( noexcept(std::cbegin(il)) );
+ static_assert( noexcept(std::cend(il)) );
+ static_assert( noexcept(std::rbegin(il)) );
+ static_assert( noexcept(std::rend(il)) );
+ static_assert( noexcept(std::crbegin(il)) );
+ static_assert( noexcept(std::crend(il)) );
+}
--- /dev/null
+// { dg-do compile { target c++17 } }
+
+#include <iterator>
+
+void
+test01()
+{
+ (void)std::cbegin({1, 2, 3}); // { dg-error "no matching function for call" }
+ (void)std::cend({1, 2, 3}); // { dg-error "no matching function for call" }
+ (void)std::rbegin({1, 2, 3}); // initializer_list overload not removed
+ (void)std::rend({1, 2, 3}); // initializer_list overload not removed
+ (void)std::crbegin({1, 2, 3}); // { dg-error "no matching function for call" }
+ (void)std::crend({1, 2, 3}); // { dg-error "no matching function for call" }
+
+}
+
+// { dg-prune-output "cannot bind non-const lvalue reference of type" }
+// { dg-prune-output "which is of non-class type" }
--- /dev/null
+// { dg-do compile { target c++17 } }
+
+#include <initializer_list>
+#include <iterator>
+
+void
+test01()
+{
+ static constexpr std::initializer_list<int> il{1};
+ static_assert( std::data(il) == il.begin() );
+ static_assert( std::size(il) == il.size() );
+ static_assert( !std::empty(il) );
+ static_assert( noexcept(std::data(il)) );
+ static_assert( noexcept(std::size(il)) );
+ static_assert( noexcept(std::empty(il)) );
+}
--- /dev/null
+// { dg-do compile { target c++17 } }
+
+#include <iterator>
+
+void
+test01()
+{
+ (void)std::data({1, 2, 3}); // { dg-error "no matching function for call" "" { target c++26 } }
+ (void)std::size({1, 2, 3}); // uses array overload
+ (void)std::empty({1, 2, 3}); // uses array overload
+}
+
+// { dg-prune-output "cannot bind non-const lvalue reference of type" }
+// { dg-prune-output "which is of non-class type" }
--- /dev/null
+// { dg-do compile { target c++11 } }
+
+#include <iterator>
+
+void
+test01()
+{
+ (void)std::begin({1, 2, 3}); // { dg-error "no matching function for call" "" { target c++26 } }
+ (void)std::end({1, 2, 3}); // { dg-error "no matching function for call" "" { target c++26 } }
+}
+
+// { dg-prune-output "cannot bind non-const lvalue reference of type" }
+// { dg-prune-output "which is of non-class type" }