[pair] Mark constructors as conditionally noexcept
Summary: std::tuple marks its constructors as noexcept when the corresponding memberwise constructors are noexcept too -- this commit improves std::pair so that it behaves the same. This is a re-application of r348824, which broke the build in C++03 mode because a test was marked as supported in C++03 when it shouldn't be. Note: I did not add support in the explicit and non-explicit `pair(_Tuple&& __p)` constructors because those are non-standard extensions, and supporting them properly is tedious (we have to copy the rvalue-referenceness of the deduced _Tuple&& onto the result of tuple_element). <rdar://problem/29537079> Reviewers: mclow.lists, EricWF Subscribers: christof, llvm-commits Differential Revision: https://reviews.llvm.org/D48669 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@348847 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
54
test/libcxx/utilities/utility/pairs/pairs.pair/U_V.pass.cpp
Normal file
54
test/libcxx/utilities/utility/pairs/pairs.pair/U_V.pass.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <utility>
|
||||
|
||||
// template <class T1, class T2> struct pair
|
||||
|
||||
// template<class U, class V> pair(U&& x, V&& y);
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
struct ExplicitT {
|
||||
constexpr explicit ExplicitT(int x) : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ImplicitT {
|
||||
constexpr ImplicitT(int x) : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ExplicitNothrowT {
|
||||
explicit ExplicitNothrowT(int x) noexcept : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ImplicitNothrowT {
|
||||
ImplicitNothrowT(int x) noexcept : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
int main() {
|
||||
{ // explicit noexcept test
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitT, ExplicitT>, int, int>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitNothrowT, ExplicitT>, int, int>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitT, ExplicitNothrowT>, int, int>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<ExplicitNothrowT, ExplicitNothrowT>, int, int>::value, "");
|
||||
}
|
||||
{ // implicit noexcept test
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitT, ImplicitT>, int, int>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitNothrowT, ImplicitT>, int, int>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitT, ImplicitNothrowT>, int, int>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<ImplicitNothrowT, ImplicitNothrowT>, int, int>::value, "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <utility>
|
||||
|
||||
// template <class T1, class T2> struct pair
|
||||
|
||||
// pair(const T1& x, const T2& y);
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
struct ExplicitT {
|
||||
constexpr explicit ExplicitT(int x) : value(x) {}
|
||||
constexpr explicit ExplicitT(ExplicitT const& o) : value(o.value) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ImplicitT {
|
||||
constexpr ImplicitT(int x) : value(x) {}
|
||||
constexpr ImplicitT(ImplicitT const& o) : value(o.value) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ExplicitNothrowT {
|
||||
explicit ExplicitNothrowT(ExplicitNothrowT const&) noexcept {}
|
||||
};
|
||||
|
||||
struct ImplicitNothrowT {
|
||||
ImplicitNothrowT(ImplicitNothrowT const&) noexcept {}
|
||||
};
|
||||
|
||||
int main() {
|
||||
{ // explicit noexcept test
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitT, ExplicitT>,
|
||||
ExplicitT const&, ExplicitT const&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitNothrowT, ExplicitT>,
|
||||
ExplicitNothrowT const&, ExplicitT const&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitT, ExplicitNothrowT>,
|
||||
ExplicitT const&, ExplicitNothrowT const&>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<ExplicitNothrowT, ExplicitNothrowT>,
|
||||
ExplicitNothrowT const&, ExplicitNothrowT const&>::value, "");
|
||||
}
|
||||
{ // implicit noexcept test
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitT, ImplicitT>,
|
||||
ImplicitT const&, ImplicitT const&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitNothrowT, ImplicitT>,
|
||||
ImplicitNothrowT const&, ImplicitT const&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitT, ImplicitNothrowT>,
|
||||
ImplicitT const&, ImplicitNothrowT const&>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<ImplicitNothrowT, ImplicitNothrowT>,
|
||||
ImplicitNothrowT const&, ImplicitNothrowT const&>::value, "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <utility>
|
||||
|
||||
// template <class T1, class T2> struct pair
|
||||
|
||||
// template <class U, class V> EXPLICIT constexpr pair(const pair<U, V>& p);
|
||||
|
||||
#include <utility>
|
||||
|
||||
|
||||
struct ExplicitT {
|
||||
constexpr explicit ExplicitT(int x) : value(x) {}
|
||||
constexpr explicit ExplicitT(ExplicitT const& o) : value(o.value) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ImplicitT {
|
||||
constexpr ImplicitT(int x) : value(x) {}
|
||||
constexpr ImplicitT(ImplicitT const& o) : value(o.value) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ExplicitNothrowT {
|
||||
explicit ExplicitNothrowT(int x) noexcept : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ImplicitNothrowT {
|
||||
ImplicitNothrowT(int x) noexcept : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
int main() {
|
||||
{ // explicit noexcept test
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitT, ExplicitT>,
|
||||
std::pair<int, int> const&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitNothrowT, ExplicitT>,
|
||||
std::pair<int, int> const&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitT, ExplicitNothrowT>,
|
||||
std::pair<int, int> const&>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<ExplicitNothrowT, ExplicitNothrowT>,
|
||||
std::pair<int, int> const&>::value, "");
|
||||
}
|
||||
{ // implicit noexcept test
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitT, ImplicitT>,
|
||||
std::pair<int, int> const&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitNothrowT, ImplicitT>,
|
||||
std::pair<int, int> const&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitT, ImplicitNothrowT>,
|
||||
std::pair<int, int> const&>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<ImplicitNothrowT, ImplicitNothrowT>,
|
||||
std::pair<int, int> const&>::value, "");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <utility>
|
||||
|
||||
// template <class T1, class T2> struct pair
|
||||
|
||||
// constexpr pair();
|
||||
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
|
||||
#include "archetypes.hpp"
|
||||
|
||||
|
||||
int main() {
|
||||
using NonThrowingDefault = NonThrowingTypes::DefaultOnly;
|
||||
using ThrowingDefault = NonTrivialTypes::DefaultOnly;
|
||||
static_assert(!std::is_nothrow_default_constructible<std::pair<ThrowingDefault, ThrowingDefault>>::value, "");
|
||||
static_assert(!std::is_nothrow_default_constructible<std::pair<NonThrowingDefault, ThrowingDefault>>::value, "");
|
||||
static_assert(!std::is_nothrow_default_constructible<std::pair<ThrowingDefault, NonThrowingDefault>>::value, "");
|
||||
static_assert( std::is_nothrow_default_constructible<std::pair<NonThrowingDefault, NonThrowingDefault>>::value, "");
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <utility>
|
||||
|
||||
// template <class T1, class T2> struct pair
|
||||
|
||||
// template <class... Args1, class... Args2>
|
||||
// pair(piecewise_construct_t, tuple<Args1...> first_args,
|
||||
// tuple<Args2...> second_args);
|
||||
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "archetypes.hpp"
|
||||
|
||||
|
||||
int main() {
|
||||
using NonThrowingConvert = NonThrowingTypes::ConvertingType;
|
||||
using ThrowingConvert = NonTrivialTypes::ConvertingType;
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ThrowingConvert, ThrowingConvert>,
|
||||
std::piecewise_construct_t, std::tuple<int, int>, std::tuple<long, long>>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<NonThrowingConvert, ThrowingConvert>,
|
||||
std::piecewise_construct_t, std::tuple<int, int>, std::tuple<long, long>>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ThrowingConvert, NonThrowingConvert>,
|
||||
std::piecewise_construct_t, std::tuple<int, int>, std::tuple<long, long>>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<NonThrowingConvert, NonThrowingConvert>,
|
||||
std::piecewise_construct_t, std::tuple<int, int>, std::tuple<long, long>>::value, "");
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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
|
||||
|
||||
// <utility>
|
||||
|
||||
// template <class T1, class T2> struct pair
|
||||
|
||||
// template <class U, class V> pair(pair<U, V>&& p);
|
||||
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
|
||||
struct ExplicitT {
|
||||
constexpr explicit ExplicitT(int x) : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ImplicitT {
|
||||
constexpr ImplicitT(int x) : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ExplicitNothrowT {
|
||||
explicit ExplicitNothrowT(int x) noexcept : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
struct ImplicitNothrowT {
|
||||
ImplicitNothrowT(int x) noexcept : value(x) {}
|
||||
int value;
|
||||
};
|
||||
|
||||
int main() {
|
||||
{ // explicit noexcept test
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitT, ExplicitT>,
|
||||
std::pair<int, int>&&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitNothrowT, ExplicitT>,
|
||||
std::pair<int, int>&&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ExplicitT, ExplicitNothrowT>,
|
||||
std::pair<int, int>&&>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<ExplicitNothrowT, ExplicitNothrowT>,
|
||||
std::pair<int, int>&&>::value, "");
|
||||
}
|
||||
{ // implicit noexcept test
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitT, ImplicitT>,
|
||||
std::pair<int, int>&&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitNothrowT, ImplicitT>,
|
||||
std::pair<int, int>&&>::value, "");
|
||||
static_assert(!std::is_nothrow_constructible<std::pair<ImplicitT, ImplicitNothrowT>,
|
||||
std::pair<int, int>&&>::value, "");
|
||||
static_assert( std::is_nothrow_constructible<std::pair<ImplicitNothrowT, ImplicitNothrowT>,
|
||||
std::pair<int, int>&&>::value, "");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user