[PATCH] D23495: Remove std::tuple's reduced-arity-extension on implicit constructors.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 15 01:07:00 PDT 2016
EricWF updated this revision to Diff 68001.
EricWF added a comment.
Add missing test case.
https://reviews.llvm.org/D23495
Files:
include/tuple
test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR27374_implicit_reduced_arity_extension_non_conforming.pass.cpp
Index: test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR27374_implicit_reduced_arity_extension_non_conforming.pass.cpp
===================================================================
--- /dev/null
+++ test/std/utilities/tuple/tuple.tuple/tuple.cnstr/PR27374_implicit_reduced_arity_extension_non_conforming.pass.cpp
@@ -0,0 +1,53 @@
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// UNSUPPORTED: c++98, c++03
+
+// <tuple>
+
+// template <class... Types> class tuple;
+
+// Check that the reduced arity constructors are never implicit.
+// See also:
+// http://llvm.org/PR27374
+// http://wg21.link/lwg2419
+
+#include <tuple>
+#include <string>
+#include <cassert>
+
+bool eat_tuple(const std::tuple<char, char>& w) { return false; }
+template <class ...Args>
+auto eat_char(Args&&... args) -> decltype(eat_tuple(args...)) { return eat_tuple(args...); }
+bool eat_char(const char&) { return true; }
+
+int count(std::tuple<std::string, std::string>) {
+ return 2;
+}
+
+int count(std::tuple<std::string, std::string, std::string>) {
+ return 3;
+}
+
+using Tup = std::tuple<int, int, int>;
+Tup explicit_still_allowed() { return Tup{1, 2}; }
+
+int main() {
+ {
+ const char ch = 'a';
+ assert(eat_char(ch));
+ }
+ {
+ assert(count({ "hungry", "zombies" }) == 2);
+ assert(count({ "cute", "fluffy", "kittens" }) == 3);
+ }
+ {
+ explicit_still_allowed();
+ }
+}
Index: include/tuple
===================================================================
--- include/tuple
+++ include/tuple
@@ -706,7 +706,7 @@
typename enable_if
<
_CheckArgsConstructor<
- sizeof...(_Up) <= sizeof...(_Tp)
+ sizeof...(_Up) == sizeof...(_Tp)
&& !_PackExpandsToThisTuple<_Up...>::value
>::template __enable_implicit<_Up...>(),
bool
@@ -735,7 +735,11 @@
_CheckArgsConstructor<
sizeof...(_Up) <= sizeof...(_Tp)
&& !_PackExpandsToThisTuple<_Up...>::value
- >::template __enable_explicit<_Up...>(),
+ >::template __enable_explicit<_Up...>() ||
+ _CheckArgsConstructor<
+ sizeof...(_Up) < sizeof...(_Tp)
+ && !_PackExpandsToThisTuple<_Up...>::value
+ >::template __enable_implicit<_Up...>(),
bool
>::type = false
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23495.68001.patch
Type: text/x-patch
Size: 2979 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160815/3bd9f778/attachment.bin>
More information about the cfe-commits
mailing list