llvm-project/libcxx/test/std
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
..
algorithms Need to wrap a bit in an ifdef, since there are no initializer_lists in C++03 2015-02-11 15:48:21 +00:00
atomics Move a test to the new tests directory. 2015-01-06 22:18:27 +00:00
containers Fix more issues exposed by -pedantic-errors in c++03 mode 2015-02-10 17:20:18 +00:00
depr Walter Brown sent a list of tests which needed 'additional includes' to match what was in the standard. Added these includes to the tests. No changes to the library or test results. 2015-01-09 20:25:52 +00:00
diagnostics libc++ implements its' hash objects as deriving from std::unary_function, and the tests test for that. STL @ MS pointed out that the standard doesn't requie these objects to derive from unary_function, and so the tests should not require that either. Change the tests to check for the embedded typedefs - which ARE required. No change to the library. 2015-01-07 21:53:23 +00:00
experimental [libcxx] Add <experimental/ratio> 2015-02-17 16:52:03 +00:00
extensions Fix more issues exposed by -pedantic-errors in c++03 mode 2015-02-10 17:20:18 +00:00
input.output Fix PR21428. Buffer was one byte too small in octal formatting case. Add test 2015-01-26 17:24:52 +00:00
iterators [libcxx] Make __wrap_iter work with gcc. 2015-01-27 19:27:39 +00:00
language.support 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
localization Rename system_lib -> system_cxx_lib. NFC 2015-01-14 23:38:12 +00:00
numerics
re Fix for PR22061 by K-ballo 2015-01-28 22:22:35 +00:00
strings Rooting out more undefined behavior in char_traits. 2015-02-13 16:04:42 +00:00
thread libc++ tests: wait_until.pass test sporadically fails (bug 21998) 2015-02-11 01:25:57 +00:00
utilities [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
nothing_to_do.pass.cpp