Skip to content

[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

Merged
merged 1 commit into from
Mar 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libcxx/docs/Status/Cxx17Issues.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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|","",""
Expand Down
2 changes: 1 addition & 1 deletion libcxx/include/initializer_list
Original file line number Diff line number Diff line change
Expand Up @@ -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_;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// 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>

#if !__has_warning("-Winvalid-specializations")
// expected-no-diagnostics
#else

// 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 0-1 {{explicit specialization of 'std::initializer_list<int>' after instantiation}}

// 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*> {};

#endif