-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Prohibits initializer_list specializations. #128042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libcxx Author: Mark de Wever (mordante) ChangesThis relies on Clang's no_specializations attribute which is not supported by GCC. Implements:
Fixes: #126270 Full diff: https://github.com/llvm/llvm-project/pull/128042.diff 3 Files Affected:
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@+2 {{'initializer_list' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <>
+class std::initializer_list<int> {};
+
+// expected-error@+2 {{'initializer_list' cannot be specialized: Users are not allowed to specialize this standard library entity}}
+template <typename T>
+class std::initializer_list<T*> {};
|
I don't know why we claimed to implement LWG2129 (#103237), but this patch does the correct thing. Thanks! |
Per 3687d3c, it seems expected that compilers would handle LWG2129 by detecting #include <initializer_list>
template<class T>
class std::initializer_list<T**> {
private:
T*** m_array_;
decltype(sizeof(0)) m_len_;
}; |
This relies on Clang's no_specializations attribute which is not supported by GCC. Implements: - LWG2129: User specializations of std::initializer_list Fixes: llvm#126270
d2dd8b0
to
451f1fb
Compare
GCC indeed only seems not to diagnose partial specialization. Clang indeed does neither, which was the reason for this patch. |
This relies on Clang's no_specializations attribute which is not supported by GCC. Implements: - LWG2129: User specializations of std::initializer_list Fixes: llvm#126270
This relies on Clang's no_specializations attribute which is not supported by GCC.
Implements:
Fixes: #126270