llvm-project/libcxx
Eric Fiselier 65500d4b29 [libc++] Try and prevent evaluation of `is_default_constructible` on tuples default constructor if it is not needed.
Summary:
Currently parts of the SFINAE on tuples default constructor always gets evaluated even when the default constructor is never called or instantiated. This can cause a hard compile error when a tuple is created with types that do not have a default constructor. Below is a self contained example using a pair like class. This code will not compile but probably should.

```

#include <type_traits>

template <class T>
struct IllFormedDefaultImp {
    IllFormedDefaultImp(T x) : value(x) {}
    constexpr IllFormedDefaultImp() {}
    T value;
};

typedef IllFormedDefaultImp<int &> IllFormedDefault;

template <class T, class U>
struct pair
{
  template <bool Dummy = true,
    class = typename std::enable_if<
         std::is_default_constructible<T>::value
      && std::is_default_constructible<U>::value
      && Dummy>::type
    >
  constexpr pair() : first(), second() {}

  pair(T const & t, U const & u) : first(t), second(u) {}

  T first;
  U second;
};

int main()
{
  int x = 1;
  IllFormedDefault v(x);
  pair<IllFormedDefault, IllFormedDefault> p(v, v);
}
```

One way to fix this is to use `Dummy` in a more involved way in the constructor SFINAE. The following patch fixes these sorts of hard compile errors for tuple.


Reviewers: mclow.lists, rsmith, K-ballo, EricWF

Reviewed By: EricWF

Subscribers: ldionne, cfe-commits

Differential Revision: http://reviews.llvm.org/D7569

llvm-svn: 230120
2015-02-21 02:30:41 +00:00
..
cmake [libcxx] Move to using libc++abi2.exp as the default symbol list for libc++ 2015-02-21 02:26:24 +00:00
include [libc++] Try and prevent evaluation of `is_default_constructible` on tuples default constructor if it is not needed. 2015-02-21 02:30:41 +00:00
lib [libcxx] Move to using libc++abi2.exp as the default symbol list for libc++ 2015-02-21 02:26:24 +00:00
src More on adding sized deallocation functions in libc++: Continuing from r229281, this adds version guards and test cases. 2015-02-20 06:13:05 +00:00
test [libc++] Try and prevent evaluation of `is_default_constructible` on tuples default constructor if it is not needed. 2015-02-21 02:30:41 +00:00
utils/not [libcxx] Allow use of ShTest in libc++ tests along with other changes. 2015-01-22 18:05:58 +00:00
www [libcxx] Tired of colorless compile errors? Enable color diagnostics today! 2015-02-18 17:39:45 +00:00
.arcconfig Update Arcanist config to point to reviews.llvm.org 2014-06-10 18:29:36 +00:00
.gitignore [libc++] Refactor test components into modules. 2015-01-09 18:03:29 +00:00
CMakeLists.txt Adopt CMake policy CMP0042. Set MACOSX_RPATH on by default. 2015-01-26 21:56:45 +00:00
CREDITS.TXT Add self to CREDITS.TXT 2015-02-20 06:17:20 +00:00
LICENSE.TXT Update the copyright credits -- Happy new year 2014! 2014-01-01 08:27:31 +00:00
Makefile Revert "Fix installheaders target's permissions" 2014-12-16 05:28:07 +00:00