-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++] Implement LWG3990 for Clang #128834
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This patch adds `[[_Clang::__no_specializations__]]` to `tuple`, with warning/error suppressed for `tuple<>`.
@llvm/pr-subscribers-libcxx Author: A. Jiang (frederick-vs-ja) ChangesThis patch adds Towards #105310. Full diff: https://github.com/llvm/llvm-project/pull/128834.diff 4 Files Affected:
diff --git a/libcxx/docs/Status/Cxx2cIssues.csv b/libcxx/docs/Status/Cxx2cIssues.csv
index 1ec23dfabd5ea..3ef7203731d83 100644
--- a/libcxx/docs/Status/Cxx2cIssues.csv
+++ b/libcxx/docs/Status/Cxx2cIssues.csv
@@ -37,7 +37,7 @@
"`LWG3973 <https://wg21.link/LWG3973>`__","Monadic operations should be ADL-proof","2023-11 (Kona)","","",""
"`LWG3974 <https://wg21.link/LWG3974>`__","``mdspan::operator[]`` should not copy ``OtherIndexTypes``","2023-11 (Kona)","","",""
"`LWG3987 <https://wg21.link/LWG3987>`__","Including ``<flat_foo>`` doesn't provide ``std::begin``/``end``","2023-11 (Kona)","","",""
-"`LWG3990 <https://wg21.link/LWG3990>`__","Program-defined specializations of ``std::tuple`` and ``std::variant`` can't be properly supported","2023-11 (Kona)","","",""
+"`LWG3990 <https://wg21.link/LWG3990>`__","Program-defined specializations of ``std::tuple`` and ``std::variant`` can't be properly supported","2023-11 (Kona)","|Partial|","21","Implemented for Clang only."
"`LWG4001 <https://wg21.link/LWG4001>`__","``iota_view`` should provide ``empty``","2023-11 (Kona)","|Complete|","19",""
"","","","","",""
"`LWG3767 <https://wg21.link/LWG3767>`__","``codecvt<charN_t, char8_t, mbstate_t>`` incorrectly added to locale","2024-03 (Tokyo)","","",""
diff --git a/libcxx/include/tuple b/libcxx/include/tuple
index 5d968bfd4015a..1e0703421da01 100644
--- a/libcxx/include/tuple
+++ b/libcxx/include/tuple
@@ -535,7 +535,7 @@ __memberwise_forward_assign(_Dest& __dest, _Source&& __source, __tuple_types<_Up
}
template <class... _Tp>
-class _LIBCPP_TEMPLATE_VIS tuple {
+class _LIBCPP_TEMPLATE_VIS _LIBCPP_NO_SPECIALIZATIONS tuple {
typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
_BaseT __base_;
@@ -1005,6 +1005,10 @@ public:
# endif // _LIBCPP_STD_VER >= 23
};
+_LIBCPP_DIAGNOSTIC_PUSH
+# if __has_warning("-Winvalid-specialization")
+_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Winvalid-specialization")
+# endif
template <>
class _LIBCPP_TEMPLATE_VIS tuple<> {
public:
@@ -1022,6 +1026,7 @@ public:
_LIBCPP_HIDE_FROM_ABI constexpr void swap(const tuple&) const noexcept {}
# endif
};
+_LIBCPP_DIAGNOSTIC_POP
# if _LIBCPP_STD_VER >= 23
template <class... _TTypes, class... _UTypes, template <class> class _TQual, template <class> class _UQual>
diff --git a/libcxx/test/libcxx/utilities/tuple/no_specializations.verify.cpp b/libcxx/test/libcxx/utilities/tuple/no_specializations.verify.cpp
new file mode 100644
index 0000000000000..783bd814a51e1
--- /dev/null
+++ b/libcxx/test/libcxx/utilities/tuple/no_specializations.verify.cpp
@@ -0,0 +1,23 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// REQUIRES: std-at-least-c++11
+
+// Check that user-specializations are diagnosed
+// See [tuple.tuple.general]/1
+
+#include <tuple>
+
+#if !__has_warning("-Winvalid-specialization")
+// expected-no-diagnostics
+#else
+struct S {};
+
+template <>
+class std::tuple<S>; // expected-error {{cannot be specialized}}
+#endif
diff --git a/libcxx/test/libcxx/utilities/no_specializations.verify.cpp b/libcxx/test/libcxx/utilities/variant/no_specializations.verify.cpp
similarity index 94%
rename from libcxx/test/libcxx/utilities/no_specializations.verify.cpp
rename to libcxx/test/libcxx/utilities/variant/no_specializations.verify.cpp
index d4743f4fd3f90..fb3b5dd63afad 100644
--- a/libcxx/test/libcxx/utilities/no_specializations.verify.cpp
+++ b/libcxx/test/libcxx/utilities/variant/no_specializations.verify.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-// UNSUPPORTED: c++03, c++11, c++14
+// REQUIRES: std-at-least-c++17
// Check that user-specializations are diagnosed
// See [variant.variant.general]/4
|
frederick-vs-ja
commented
Feb 26, 2025
philnik777
requested changes
Feb 26, 2025
libcxx/test/libcxx/utilities/variant/no_specializations.verify.cpp
Outdated
Show resolved
Hide resolved
philnik777
approved these changes
Feb 26, 2025
This comment was marked as resolved.
This comment was marked as resolved.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch adds
[[_Clang::__no_specializations__]]
totuple
, with warning/error suppressed fortuple<>
.Fixes #105310.