Skip to content

Commit f5f5286

Browse files
[libc++] Implement LWG3990 for Clang (#128834)
This patch adds `[[_Clang::__no_specializations__]]` to `tuple`, with warning/error suppressed for `tuple<>`.
1 parent d403f33 commit f5f5286

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

libcxx/docs/Status/Cxx2cIssues.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"`LWG3973 <https://wg21.link/LWG3973>`__","Monadic operations should be ADL-proof","2023-11 (Kona)","","",""
3838
"`LWG3974 <https://wg21.link/LWG3974>`__","``mdspan::operator[]`` should not copy ``OtherIndexTypes``","2023-11 (Kona)","","",""
3939
"`LWG3987 <https://wg21.link/LWG3987>`__","Including ``<flat_foo>`` doesn't provide ``std::begin``/``end``","2023-11 (Kona)","","",""
40-
"`LWG3990 <https://wg21.link/LWG3990>`__","Program-defined specializations of ``std::tuple`` and ``std::variant`` can't be properly supported","2023-11 (Kona)","","",""
40+
"`LWG3990 <https://wg21.link/LWG3990>`__","Program-defined specializations of ``std::tuple`` and ``std::variant`` can't be properly supported","2023-11 (Kona)","|Complete|","21",""
4141
"`LWG4001 <https://wg21.link/LWG4001>`__","``iota_view`` should provide ``empty``","2023-11 (Kona)","|Complete|","19",""
4242
"","","","","",""
4343
"`LWG3767 <https://wg21.link/LWG3767>`__","``codecvt<charN_t, char8_t, mbstate_t>`` incorrectly added to locale","2024-03 (Tokyo)","","",""

libcxx/include/tuple

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up
535535
}
536536

537537
template <class... _Tp>
538-
class _LIBCPP_TEMPLATE_VIS tuple {
538+
class _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS tuple {
539539
typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
540540

541541
_BaseT __base_;
@@ -1005,6 +1005,10 @@ public:
10051005
# endif // _LIBCPP_STD_VER >= 23
10061006
};
10071007

1008+
_LIBCPP_DIAGNOSTIC_PUSH
1009+
# if __has_warning("-Winvalid-specialization")
1010+
_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
1011+
# endif
10081012
template <>
10091013
class _LIBCPP_TEMPLATE_VIS tuple<> {
10101014
public:
@@ -1022,6 +1026,7 @@ public:
10221026
_LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
10231027
# endif
10241028
};
1029+
_LIBCPP_DIAGNOSTIC_POP
10251030

10261031
# if _LIBCPP_STD_VER >= 23
10271032
template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++11
10+
11+
// Check that user-specializations are diagnosed
12+
// See [tuple.tuple.general]/1
13+
14+
#include <tuple>
15+
16+
#if !__has_warning("-Winvalid-specialization")
17+
// expected-no-diagnostics
18+
#else
19+
struct S {};
20+
21+
template <>
22+
class std::tuple<S>; // expected-error {{cannot be specialized}}
23+
#endif

0 commit comments

Comments
 (0)