[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:04:35 PDT 2016


EricWF created this revision.
EricWF added reviewers: mclow.lists, rsmith.
EricWF added a subscriber: cfe-commits.

The reduced-arity-extension on tuple's implicit constructors breaks conforming code. eg

```
#include <tuple>
#include <string>
using namespace std;
int count(tuple<string, string>) { return 2; }
int count(tuple<string, string, string>) { return 3; }

int main() {
  int c = count({"abc", "def"}); // expected-error {{call to 'count' is ambiguous}}
}
```

To fix this the I removed the reduced-arity-extension only on the implicit constructors. This breaks the following code:

```
std::tuple<int, int, int> foo() { return {1, 2}  }
```

But it still allows for
```
using Tup = std::tuple<int, int, int>;
Tup foo() { return Tup{1, 2}; } 
```

@Marshall should we provide a way to turn this ctor back on in case in breaks a bunch of real-world code? Maybe deprecate it for a release?

See also:
  * http://llvm.org/PR27374
  * http://wg21.link/lwg2419

https://reviews.llvm.org/D23495

Files:
  include/tuple

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
@@ -716,26 +716,30 @@
         tuple(_Up&&... __u)
             _NOEXCEPT_((
                 is_nothrow_constructible<base,
-                    typename __make_tuple_indices<sizeof...(_Up)>::type,
-                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
-                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
-                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
+                    typename __make_tuple_indices<sizeof...(_Tp)>::type,
+                    __tuple_types<_Tp...>,
+                    __tuple_indices<>,
+                    __tuple_types<>,
                     _Up...
                 >::value
             ))
-            : base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
-                    typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
-                    typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
-                    typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
+            : base_(typename __make_tuple_indices<sizeof...(_Tp)>::type{},
+                    __tuple_types<_Tp...>{},
+                    __tuple_indices<>{},
+                    __tuple_types<>{},
                     _VSTD::forward<_Up>(__u)...) {}
 
     template <class ..._Up,
               typename enable_if
                       <
                          _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.67998.patch
Type: text/x-patch
Size: 2631 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160815/ead6da48/attachment.bin>


More information about the cfe-commits mailing list