Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[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 llvm-svn: 348847
- Loading branch information
Showing
10 changed files
with
388 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/U_V.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, ""); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/const_first_const_second.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, ""); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/const_pair_U_V.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, ""); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/default.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, ""); | ||
} |
38 changes: 38 additions & 0 deletions
38
libcxx/test/libcxx/utilities/utility/pairs/pairs.pair/piecewise.pass.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, ""); | ||
} |
Oops, something went wrong.