[libcxx-commits] [libcxx] [libc++] Prohibits initializer_list specializations. (PR #128042)
Mark de Wever via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Feb 20 10:18:14 PST 2025
https://github.com/mordante created https://github.com/llvm/llvm-project/pull/128042
This relies on Clang's no_specializations attribute which is not supported by GCC.
Implements:
- LWG2129: User specializations of std::initializer_list
Fixes: #126270
>From d2dd8b08bc12071cf63efdc5b8a8613d1af79d99 Mon Sep 17 00:00:00 2001
From: Mark de Wever <koraq at xs4all.nl>
Date: Thu, 20 Feb 2025 19:13:58 +0100
Subject: [PATCH] [libc++] Prohibits initializer_list specializations.
This relies on Clang's no_specializations attribute which is not
supported by GCC.
Implements:
- LWG2129: User specializations of std::initializer_list
Fixes: #126270
---
libcxx/docs/Status/Cxx17Issues.csv | 2 +-
libcxx/include/initializer_list | 2 +-
.../specialization.verify.cpp | 24 +++++++++++++++++++
3 files changed, 26 insertions(+), 2 deletions(-)
create mode 100644 libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp
diff --git a/libcxx/docs/Status/Cxx17Issues.csv b/libcxx/docs/Status/Cxx17Issues.csv
index 477f3d363a4e2..d09b37f1d3900 100644
--- a/libcxx/docs/Status/Cxx17Issues.csv
+++ b/libcxx/docs/Status/Cxx17Issues.csv
@@ -12,7 +12,7 @@
"`LWG2404 <https://wg21.link/LWG2404>`__","``mismatch()``\ 's complexity needs to be updated","2014-11 (Urbana)","|Complete|","",""
"`LWG2408 <https://wg21.link/LWG2408>`__","SFINAE-friendly ``common_type``\ / ``iterator_traits``\ is missing in C++14","2014-11 (Urbana)","|Complete|","",""
"`LWG2106 <https://wg21.link/LWG2106>`__","``move_iterator``\ wrapping iterators returning prvalues","2014-11 (Urbana)","|Complete|","",""
-"`LWG2129 <https://wg21.link/LWG2129>`__","User specializations of ``std::initializer_list``\ ","2014-11 (Urbana)","|Complete|","",""
+"`LWG2129 <https://wg21.link/LWG2129>`__","User specializations of ``std::initializer_list``\ ","2014-11 (Urbana)","|Complete|","21",""
"`LWG2212 <https://wg21.link/LWG2212>`__","``tuple_size``\ for ``const pair``\ request <tuple> header","2014-11 (Urbana)","|Complete|","",""
"`LWG2217 <https://wg21.link/LWG2217>`__","``operator==(sub_match, string)``\ slices on embedded '\0's","2014-11 (Urbana)","|Complete|","",""
"`LWG2230 <https://wg21.link/LWG2230>`__","""see below"" for ``initializer_list``\ constructors of unordered containers","2014-11 (Urbana)","|Complete|","",""
diff --git a/libcxx/include/initializer_list b/libcxx/include/initializer_list
index 07c51f32fee7d..3967ad8aaef7c 100644
--- a/libcxx/include/initializer_list
+++ b/libcxx/include/initializer_list
@@ -59,7 +59,7 @@ namespace std // purposefully not versioned
# ifndef _LIBCPP_CXX03_LANG
template <class _Ep>
-class _LIBCPP_TEMPLATE_VIS initializer_list {
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS initializer_list {
const _Ep* __begin_;
size_t __size_;
diff --git a/libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp b/libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp
new file mode 100644
index 0000000000000..5ea36a47cee1a
--- /dev/null
+++ b/libcxx/test/std/language.support/support.initlist/support.initlist.syn/specialization.verify.cpp
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: c++03
+
+// template<class E> class initializer_list;
+//
+// If an explicit specialization or partial specialization of initializer_list
+// is declared, the program is ill-formed.
+
+#include <initializer_list>
+
+// expected-error at +2 {{'initializer_list' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <>
+class std::initializer_list<int> {};
+
+// expected-error at +2 {{'initializer_list' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <typename T>
+class std::initializer_list<T*> {};
More information about the libcxx-commits
mailing list