From 932604f8d1f8bdc196efea09d701cf4eba614502 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 25 Jul 2016 00:48:36 +0000 Subject: [PATCH] Don't SFINAE pair's copy assignment operator in C++03 mode. In C++03 mode evaluating the SFINAE can cause a hard error due to access control violations. This is a problem because the SFINAE is evaluated as soon as the class is instantiated, and not later. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276594 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/utility | 4 +++ .../pairs.pair/assign_pair_cxx03.pass.cpp | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp diff --git a/include/utility b/include/utility index 66c3dd4c5..9a155a00f 100644 --- a/include/utility +++ b/include/utility @@ -351,9 +351,13 @@ struct _LIBCPP_TYPE_VIS_ONLY pair typedef typename remove_reference<_T1>::type _T1Unref; typedef typename remove_reference<_T2>::type _T2Unref; +#if !defined(_LIBCPP_CXX03_LANG) typedef integral_constant::value && is_copy_assignable<_T2>::value> _CanCopyAssign; +#else + typedef true_type _CanCopyAssign; +#endif _LIBCPP_INLINE_VISIBILITY pair& operator=(typename conditional<_CanCopyAssign::value, pair, __nat>::type const& __p) diff --git a/test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp b/test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp new file mode 100644 index 000000000..8b9d1ed89 --- /dev/null +++ b/test/std/utilities/utility/pairs/pairs.pair/assign_pair_cxx03.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// 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. +// +//===----------------------------------------------------------------------===// + +// REQUIRES-ANY: c++98, c++03 + +// + +// template struct pair + +// pair& operator=(pair const& p); + +#include +#include +#include + + +struct NonAssignable { + NonAssignable() {} +private: + NonAssignable& operator=(NonAssignable const&); +}; + +int main() +{ + // Test that we don't constrain the assignment operator in C++03 mode. + // Since we don't have access control SFINAE having pair evaluate SFINAE + // may cause a hard error. + typedef std::pair P; + static_assert(std::is_copy_assignable

::value, ""); +}