Implement std::experimental::fundamentals_v2::propagate_const.

2015-07-03  Ville Voutilainen  <ville.voutilainen@gmail.com>

	Implement std::experimental::fundamentals_v2::propagate_const.
	* include/Makefile.am: Add propagate_const.
	* include/Makefile.in: Regenerate.
	* include/experimental/propagate_const: New.
	* testsuite/experimental/propagate_const/assignment/copy.cc: Likewise.
	* testsuite/experimental/propagate_const/assignment/move.cc: Likewise.
	* testsuite/experimental/propagate_const/assignment/move_neg.cc:
	Likewise.
	* testsuite/experimental/propagate_const/cons/copy.cc: Likewise.
	* testsuite/experimental/propagate_const/cons/default.cc: Likewise.
	* testsuite/experimental/propagate_const/cons/move.cc: Likewise.
	* testsuite/experimental/propagate_const/cons/move_neg.cc: Likewise.
	* testsuite/experimental/propagate_const/hash/1.cc: Likewise.
	* testsuite/experimental/propagate_const/observers/1.cc: Likewise.
	* testsuite/experimental/propagate_const/relops/1.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements1.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements2.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements3.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements4.cc: Likewise.
	* testsuite/experimental/propagate_const/requirements5.cc: Likewise.
	* testsuite/experimental/propagate_const/swap/1.cc: Likewise.
	* testsuite/experimental/propagate_const/typedefs.cc: Likewise.

From-SVN: r225379
This commit is contained in:
Ville Voutilainen 2015-07-03 17:08:37 +03:00 committed by Jonathan Wakely
parent 805a54065f
commit e37e6813d5
21 changed files with 1214 additions and 0 deletions

View File

@ -1,3 +1,28 @@
2015-07-03 Ville Voutilainen <ville.voutilainen@gmail.com>
Implement std::experimental::fundamentals_v2::propagate_const.
* include/Makefile.am: Add propagate_const.
* include/Makefile.in: Regenerate.
* include/experimental/propagate_const: New.
* testsuite/experimental/propagate_const/assignment/copy.cc: Likewise.
* testsuite/experimental/propagate_const/assignment/move.cc: Likewise.
* testsuite/experimental/propagate_const/assignment/move_neg.cc:
Likewise.
* testsuite/experimental/propagate_const/cons/copy.cc: Likewise.
* testsuite/experimental/propagate_const/cons/default.cc: Likewise.
* testsuite/experimental/propagate_const/cons/move.cc: Likewise.
* testsuite/experimental/propagate_const/cons/move_neg.cc: Likewise.
* testsuite/experimental/propagate_const/hash/1.cc: Likewise.
* testsuite/experimental/propagate_const/observers/1.cc: Likewise.
* testsuite/experimental/propagate_const/relops/1.cc: Likewise.
* testsuite/experimental/propagate_const/requirements1.cc: Likewise.
* testsuite/experimental/propagate_const/requirements2.cc: Likewise.
* testsuite/experimental/propagate_const/requirements3.cc: Likewise.
* testsuite/experimental/propagate_const/requirements4.cc: Likewise.
* testsuite/experimental/propagate_const/requirements5.cc: Likewise.
* testsuite/experimental/propagate_const/swap/1.cc: Likewise.
* testsuite/experimental/propagate_const/typedefs.cc: Likewise.
2015-07-02 Jonathan Wakely <jwakely@redhat.com>
* acinclude.m4 (GLIBCXX_DEFAULT_ABI): Change valid arguments for

View File

@ -657,6 +657,7 @@ experimental_headers = \
${experimental_srcdir}/memory \
${experimental_srcdir}/numeric \
${experimental_srcdir}/optional \
${experimental_srcdir}/propagate_const \
${experimental_srcdir}/ratio \
${experimental_srcdir}/set \
${experimental_srcdir}/string \

View File

@ -946,6 +946,7 @@ experimental_headers = \
${experimental_srcdir}/memory \
${experimental_srcdir}/numeric \
${experimental_srcdir}/optional \
${experimental_srcdir}/propagate_const \
${experimental_srcdir}/ratio \
${experimental_srcdir}/set \
${experimental_srcdir}/string \

View File

@ -0,0 +1,535 @@
// <experimental/propagate_const> -*- C++ -*-
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.
// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.
/** @file experimental/propagate_const
* This is a TS C++ Library header.
*/
#ifndef _GLIBCXX_EXPERIMENTAL_PROPAGATE_CONST
#define _GLIBCXX_EXPERIMENTAL_PROPAGATE_CONST 1
#pragma GCC system_header
#if __cplusplus <= 201103L
# include <bits/c++14_warning.h>
#else
#include <type_traits>
#include <functional>
namespace std _GLIBCXX_VISIBILITY(default)
{
namespace experimental
{
inline namespace fundamentals_v2
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
/**
* @defgroup propagate_const Const-propagating wrapper
* @ingroup experimental
*
* A const-propagating wrapper that propagates const to pointer-like members,
* as described in n4388 "A Proposal to Add a Const-Propagating Wrapper
* to the Standard Library".
*
* @{
*/
/// Const-propagating wrapper.
template <typename _Tp>
class propagate_const
{
public:
typedef remove_reference_t<decltype(*declval<_Tp&>())> element_type;
private:
template <typename _Up>
struct __is_propagate_const : false_type
{ };
template <typename _Up>
struct __is_propagate_const<propagate_const<_Up>> : true_type
{ };
template <typename _Up>
friend constexpr const _Up&
get_underlying(const propagate_const<_Up>& __pt) noexcept;
template <typename _Up>
friend constexpr _Up&
get_underlying(propagate_const<_Up>& __pt) noexcept;
template <typename _Up>
static constexpr element_type*
__to_raw_pointer(_Up* __u)
{ return __u; }
template <typename _Up>
static constexpr element_type*
__to_raw_pointer(_Up& __u)
{ return __u.get(); }
template <typename _Up>
static constexpr const element_type*
__to_raw_pointer(const _Up* __u)
{ return __u; }
template <typename _Up>
static constexpr const element_type*
__to_raw_pointer(const _Up& __u)
{ return __u.get(); }
public:
static_assert(__and_<is_object<typename remove_pointer<_Tp>::type>,
__not_<is_array<_Tp>>,
__or_<is_class<_Tp>, is_pointer<_Tp>>>::value,
"propagate_const requires a class or a pointer to an"
" object type");
// [propagate_const.ctor], constructors
constexpr propagate_const() = default;
propagate_const(const propagate_const& __p) = delete;
constexpr propagate_const(propagate_const&& __p) = default;
template <typename _Up, typename
enable_if<__and_<is_constructible<_Tp, _Up&&>,
is_convertible<_Up&&, _Tp>>::value, bool
>::type=true>
constexpr propagate_const(propagate_const<_Up>&& __pu)
: __t(move(get_underlying(__pu)))
{}
template <typename _Up, typename
enable_if<__and_<is_constructible<_Tp, _Up&&>,
__not_<is_convertible<_Up&&, _Tp>>>::value,
bool>::type=false>
constexpr explicit propagate_const(propagate_const<_Up>&& __pu)
: __t(move(get_underlying(__pu)))
{}
template <typename _Up, typename
enable_if<__and_<is_constructible<_Tp, _Up&&>,
is_convertible<_Up&&, _Tp>,
__not_<__is_propagate_const<
typename decay<_Up>::type>>
>::value, bool>::type=true>
constexpr propagate_const(_Up&& __u)
: __t(forward<_Up>(__u))
{}
template <typename _Up, typename
enable_if<__and_<is_constructible<_Tp, _Up&&>,
__not_<is_convertible<_Up&&, _Tp>>,
__not_<__is_propagate_const<
typename decay<_Up>::type>>
>::value, bool>::type=false>
constexpr explicit propagate_const(_Up&& __u)
: __t(forward<_Up>(__u))
{}
// [propagate_const.assignment], assignment
propagate_const& operator=(const propagate_const& __p) = delete;
constexpr propagate_const& operator=(propagate_const&& __p) = default;
template <typename _Up, typename =
typename enable_if<is_convertible<_Up&&, _Tp>::value>::type>
constexpr propagate_const& operator=(propagate_const<_Up>&& __pu)
{
__t = move(get_underlying(__pu));
}
template <typename _Up, typename =
typename enable_if<__and_<is_convertible<_Up&&, _Tp>,
__not_<__is_propagate_const<
typename decay<_Up>::type>>
>::value>::type>
constexpr propagate_const& operator=(_Up&& __u)
{
__t = forward<_Up>(__u);
}
// [propagate_const.const_observers], const observers
explicit constexpr operator bool() const
{
return bool(__t);
}
constexpr const element_type* operator->() const
{
return get();
}
template <typename _Up = _Tp,
typename enable_if<__or_<is_pointer<_Up>,
is_convertible<_Up,
const element_type*>
>::value, bool>::type = true>
constexpr operator const element_type*() const
{
return get();
}
constexpr const element_type& operator*() const
{
return *get();
}
constexpr const element_type* get() const
{
return __to_raw_pointer(__t);
}
// [propagate_const.non_const_observers], non-const observers
constexpr element_type* operator->()
{
return get();
}
template <typename _Up = _Tp,
typename enable_if<__or_<is_pointer<_Up>,
is_convertible<_Up,
const element_type*>
>::value, bool>::type = true>
constexpr operator element_type*()
{
return get();
}
constexpr element_type& operator*()
{
return *get();
}
constexpr element_type* get()
{
return __to_raw_pointer(__t);
}
// [propagate_const.modifiers], modifiers
constexpr void
swap(propagate_const& __pt) noexcept(__is_nothrow_swappable<_Tp>::value)
{
using std::swap;
swap(__t, get_underlying(__pt));
}
private:
_Tp __t; //exposition only
};
// [propagate_const.relational], relational operators
template <typename _Tp>
constexpr bool
operator==(const propagate_const<_Tp>& __pt, nullptr_t)
{
return get_underlying(__pt) == nullptr;
}
template <typename _Tp>
constexpr bool
operator==(nullptr_t, const propagate_const<_Tp>& __pu)
{
return nullptr == get_underlying(__pu);
}
template <typename _Tp>
constexpr bool
operator!=(const propagate_const<_Tp>& __pt, nullptr_t)
{
return get_underlying(__pt) != nullptr;
}
template <typename _Tp>
constexpr bool operator!=(nullptr_t, const propagate_const<_Tp>& __pu)
{
return nullptr != get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator==(const propagate_const<_Tp>& __pt,
const propagate_const<_Up>& __pu)
{
return get_underlying(__pt) == get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator!=(const propagate_const<_Tp>& __pt,
const propagate_const<_Up>& __pu)
{
return get_underlying(__pt) != get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator<(const propagate_const<_Tp>& __pt,
const propagate_const<_Up>& __pu)
{
return get_underlying(__pt) < get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator>(const propagate_const<_Tp>& __pt,
const propagate_const<_Up>& __pu)
{
return get_underlying(__pt) > get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator<=(const propagate_const<_Tp>& __pt,
const propagate_const<_Up>& __pu)
{
return get_underlying(__pt) <= get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator>=(const propagate_const<_Tp>& __pt,
const propagate_const<_Up>& __pu)
{
return get_underlying(__pt) >= get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator==(const propagate_const<_Tp>& __pt, const _Up& __u)
{
return get_underlying(__pt) == __u;
}
template <typename _Tp, typename _Up>
constexpr bool
operator!=(const propagate_const<_Tp>& __pt, const _Up& __u)
{
return get_underlying(__pt) != __u;
}
template <typename _Tp, typename _Up>
constexpr bool
operator<(const propagate_const<_Tp>& __pt, const _Up& __u)
{
return get_underlying(__pt) < __u;
}
template <typename _Tp, typename _Up>
constexpr bool
operator>(const propagate_const<_Tp>& __pt, const _Up& __u)
{
return get_underlying(__pt) > __u;
}
template <typename _Tp, typename _Up>
constexpr bool
operator<=(const propagate_const<_Tp>& __pt, const _Up& __u)
{
return get_underlying(__pt) <= __u;
}
template <typename _Tp, typename _Up>
constexpr bool
operator>=(const propagate_const<_Tp>& __pt, const _Up& __u)
{
return get_underlying(__pt) >= __u;
}
template <typename _Tp, typename _Up>
constexpr bool
operator==(const _Tp& __t, const propagate_const<_Up>& __pu)
{
return __t == get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator!=(const _Tp& __t, const propagate_const<_Up>& __pu)
{
return __t != get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator<(const _Tp& __t, const propagate_const<_Up>& __pu)
{
return __t < get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator>(const _Tp& __t, const propagate_const<_Up>& __pu)
{
return __t > get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator<=(const _Tp& __t, const propagate_const<_Up>& __pu)
{
return __t <= get_underlying(__pu);
}
template <typename _Tp, typename _Up>
constexpr bool
operator>=(const _Tp& __t, const propagate_const<_Up>& __pu)
{
return __t >= get_underlying(__pu);
}
// [propagate_const.algorithms], specialized algorithms
template <typename _Tp>
constexpr void
swap(propagate_const<_Tp>& __pt, propagate_const<_Tp>& __pt2)
noexcept(__is_nothrow_swappable<_Tp>::value)
{
__pt.swap(__pt2);
}
// [propagate_const.underlying], underlying pointer access
template <typename _Tp>
constexpr const _Tp&
get_underlying(const propagate_const<_Tp>& __pt) noexcept
{
return __pt.__t;
}
template <typename _Tp>
constexpr _Tp&
get_underlying(propagate_const<_Tp>& __pt) noexcept
{
return __pt.__t;
}
// @} group propagate_const
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace fundamentals_v2
} // namespace experimental
// [propagate_const.hash], hash support
template <typename _Tp>
struct hash<experimental::propagate_const<_Tp>>
{
using result_type = size_t;
using argument_type = experimental::propagate_const<_Tp>;
size_t
operator()(const experimental::propagate_const<_Tp>& __t) const
noexcept(noexcept(hash<_Tp>{}(get_underlying(__t))))
{
return hash<_Tp>{}(get_underlying(__t));
}
};
// [propagate_const.comparison_function_objects], comparison function objects
template <typename _Tp>
struct equal_to<experimental::propagate_const<_Tp>>
{
constexpr bool
operator()(const experimental::propagate_const<_Tp>& __x,
const experimental::propagate_const<_Tp>& __y) const
{
return equal_to<_Tp>{}(get_underlying(__x), get_underlying(__y));
}
typedef experimental::propagate_const<_Tp> first_argument_type;
typedef experimental::propagate_const<_Tp> second_argument_type;
typedef bool result_type;
};
template <typename _Tp>
struct not_equal_to<experimental::propagate_const<_Tp>>
{
constexpr bool
operator()(const experimental::propagate_const<_Tp>& __x,
const experimental::propagate_const<_Tp>& __y) const
{
return not_equal_to<_Tp>{}(get_underlying(__x), get_underlying(__y));
}
typedef experimental::propagate_const<_Tp> first_argument_type;
typedef experimental::propagate_const<_Tp> second_argument_type;
typedef bool result_type;
};
template <typename _Tp>
struct less<experimental::propagate_const<_Tp>>
{
constexpr bool
operator()(const experimental::propagate_const<_Tp>& __x,
const experimental::propagate_const<_Tp>& __y) const
{
return less<_Tp>{}(get_underlying(__x), get_underlying(__y));
}
typedef experimental::propagate_const<_Tp> first_argument_type;
typedef experimental::propagate_const<_Tp> second_argument_type;
typedef bool result_type;
};
template <typename _Tp>
struct greater<experimental::propagate_const<_Tp>>
{
constexpr bool
operator()(const experimental::propagate_const<_Tp>& __x,
const experimental::propagate_const<_Tp>& __y) const
{
return greater<_Tp>{}(get_underlying(__x), get_underlying(__y));
}
typedef experimental::propagate_const<_Tp> first_argument_type;
typedef experimental::propagate_const<_Tp> second_argument_type;
typedef bool result_type;
};
template <typename _Tp>
struct less_equal<experimental::propagate_const<_Tp>>
{
constexpr bool
operator()(const experimental::propagate_const<_Tp>& __x,
const experimental::propagate_const<_Tp>& __y) const
{
return less_equal<_Tp>{}(get_underlying(__x), get_underlying(__y));
}
typedef experimental::propagate_const<_Tp> first_argument_type;
typedef experimental::propagate_const<_Tp> second_argument_type;
typedef bool result_type;
};
template <typename _Tp>
struct greater_equal<experimental::propagate_const<_Tp>>
{
constexpr bool
operator()(const experimental::propagate_const<_Tp>& __x,
const experimental::propagate_const<_Tp>& __y) const
{
return greater_equal<_Tp>{}(get_underlying(__x), get_underlying(__y));
}
typedef experimental::propagate_const<_Tp> first_argument_type;
typedef experimental::propagate_const<_Tp> second_argument_type;
typedef bool result_type;
};
} // namespace std
#endif // C++14
#endif // _GLIBCXX_EXPERIMENTAL_PROPAGATE_CONST

View File

@ -0,0 +1,32 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
using std::experimental::propagate_const;
int main()
{
int dummy;
propagate_const<int*> test1;
propagate_const<int*> test2;
test2 = test1; // { dg-error "deleted" }
test2 = &dummy;
}

View File

@ -0,0 +1,47 @@
// { dg-options "-std=gnu++14" }
// { dg-do run }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
#include <utility>
#include <memory>
using std::experimental::propagate_const;
using std::unique_ptr;
int main()
{
const int dummy{42};
propagate_const<const int*> test1;
test1 = std::move(&dummy);
test1 = &dummy;
VERIFY(test1.get() == &dummy);
propagate_const<const int*> test2;
test2 = std::move(test1);
VERIFY(test1.get() == &dummy);
VERIFY(test2.get() == &dummy);
propagate_const<const int*> test3;
test3 = std::move(test2);
VERIFY(test1.get() == &dummy);
VERIFY(test2.get() == &dummy);
VERIFY(test3.get() == &dummy);
propagate_const<unique_ptr<const int>> test4;
test4 = std::make_unique<int>(666);
}

View File

@ -0,0 +1,38 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
#include <utility>
#include <memory>
using std::experimental::propagate_const;
using std::unique_ptr;
// { dg-error "no type" "" { target *-*-* } 158 }
int main()
{
propagate_const<unique_ptr<const int>> test5;
test5 = new int{666}; // { dg-error "no match" }
const int* dummy2 = new int{666};
propagate_const<unique_ptr<const int>> test6;
test6 = dummy2; // { dg-error "no match" }
}

View File

@ -0,0 +1,30 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
using std::experimental::propagate_const;
int main()
{
propagate_const<int*> test1;
propagate_const<int*> test2{test1}; // { dg-error "deleted" }
propagate_const<int*> test3 = test1; // { dg-error "deleted" }
}

View File

@ -0,0 +1,32 @@
// { dg-options "-std=gnu++14" }
// { dg-do run }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
using std::experimental::propagate_const;
int main()
{
constexpr propagate_const<int*> test1{};
static_assert(!test1.get(), "");
propagate_const<int*> test2;
VERIFY(!test2.get());
}

View File

@ -0,0 +1,45 @@
// { dg-options "-std=gnu++14" }
// { dg-do run }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
#include <utility>
#include <memory>
using std::experimental::propagate_const;
using std::unique_ptr;
int main()
{
const int dummy{42};
propagate_const<const int*> test1{&dummy};
VERIFY(test1.get() == &dummy);
propagate_const<const int*> test2{std::move(test1)};
VERIFY(test1.get() == &dummy);
VERIFY(test2.get() == &dummy);
propagate_const<const int*> test3{std::move(test2)};
VERIFY(test1.get() == &dummy);
VERIFY(test2.get() == &dummy);
VERIFY(test3.get() == &dummy);
propagate_const<unique_ptr<const int>> test4{std::make_unique<int>(666)};
propagate_const<unique_ptr<const int>> test5{new int{666}};
const int* dummy2 = new int{666};
propagate_const<unique_ptr<const int>> test6{dummy2};
}

View File

@ -0,0 +1,42 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
#include <utility>
#include <memory>
using std::experimental::propagate_const;
using std::unique_ptr;
// { dg-error "no type" "" { target *-*-* } 117 }
// { dg-error "no type" "" { target *-*-* } 124 }
// { dg-error "no type" "" { target *-*-* } 133 }
// { dg-error "no type" "" { target *-*-* } 142 }
int main()
{
const int dummy{42};
propagate_const<const int*> test1{&dummy};
propagate_const<int*> test2{&dummy}; // { dg-error "no matching function" }
propagate_const<int*> test3{std::move(test1)}; // { dg-error "no matching function" }
propagate_const<unique_ptr<const int>> test4 = &dummy; // { dg-error "conversion" }
propagate_const<unique_ptr<const int>> test5 = std::move(test1); // { dg-error "conversion" }
}

View File

@ -0,0 +1,35 @@
// { dg-options "-std=gnu++14" }
// { dg-do run }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
using std::experimental::propagate_const;
using std::hash;
int main()
{
int x{42};
int y{666};
propagate_const<int*> xx{&x};
propagate_const<int*> yy{&y};
VERIFY(hash<int*>{}(&x) == hash<propagate_const<int*>>{}(xx));
VERIFY(hash<int*>{}(&y) == hash<propagate_const<int*>>{}(yy));
}

View File

@ -0,0 +1,65 @@
// { dg-options "-std=gnu++14" }
// { dg-do run }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
using std::experimental::propagate_const;
using std::hash;
int main()
{
int x{42};
propagate_const<int*> xx{&x};
VERIFY(bool(xx));
propagate_const<int*> xx2{};
VERIFY(!bool(xx2));
struct X {int x;};
X x3{42};
propagate_const<X*> xx3{&x3};
VERIFY(xx3->x == 42);
VERIFY((*xx3).x == 42);
VERIFY(xx3.get() == &x3);
const propagate_const<X*> xx4{&x3};
VERIFY(xx4->x == 42);
VERIFY((*xx4).x == 42);
VERIFY(xx4.get() == &x3);
static constexpr int x4{42};
constexpr propagate_const<const int*> xx5{&x4};
static_assert(bool(xx5), "");
constexpr propagate_const<const int*> xx6{};
static_assert(!bool(xx6), "");
struct X2 {int x;};
static constexpr X2 x5{42};
constexpr propagate_const<const X2*> xx7{&x5};
static_assert(xx7->x == 42, "");
static_assert((*xx7).x == 42, "");
static_assert(xx7.get() == &x5, "");
struct X3
{
int f() {return 42;}
int f() const {return 666;}
};
X3 xx8;
propagate_const<X3*> xx9{&xx8};
const propagate_const<X3*> xx10{&xx8};
VERIFY(xx9->f() == 42);
VERIFY(xx10->f() == 666);
}

View File

@ -0,0 +1,67 @@
// { dg-options "-std=gnu++14" }
// { dg-do run }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
using std::experimental::propagate_const;
using std::hash;
int main()
{
int x[2];
propagate_const<int*> xx1{&x[0]};
propagate_const<int*> xx2{&x[1]};
VERIFY(xx1 == xx1);
VERIFY(xx1 != xx2);
VERIFY(xx1 < xx2);
VERIFY(xx2 > xx1);
VERIFY(xx1 <= xx2);
VERIFY(xx2 >= xx1);
VERIFY(xx1 <= xx1);
VERIFY(xx2 >= xx2);
VERIFY(std::equal_to<propagate_const<int*>>{}(xx1, xx1));
VERIFY(std::not_equal_to<propagate_const<int*>>{}(xx1, xx2));
VERIFY(std::less<propagate_const<int*>>{}(xx1, xx2));
VERIFY(std::greater<propagate_const<int*>>{}(xx2, xx1));
VERIFY(std::less_equal<propagate_const<int*>>{}(xx1, xx2));
VERIFY(std::greater_equal<propagate_const<int*>>{}(xx2, xx1));
VERIFY(std::less_equal<propagate_const<int*>>{}(xx1, xx1));
VERIFY(std::greater_equal<propagate_const<int*>>{}(xx2, xx2));
static constexpr int x2[2]{};
constexpr propagate_const<const int*> xx3{&x2[0]};
constexpr propagate_const<const int*> xx4{&x2[1]};
static_assert(xx3 == xx3, "");
static_assert(xx3 != xx4, "");
static_assert(xx3 < xx4, "");
static_assert(xx4 > xx3, "");
static_assert(xx3 <= xx4, "");
static_assert(xx4 >= xx3, "");
static_assert(xx3 <= xx3, "");
static_assert(xx4 >= xx4, "");
static_assert(std::equal_to<propagate_const<const int*>>{}(xx3, xx3), "");
static_assert(std::not_equal_to<propagate_const<const int*>>{}(xx3, xx4), "");
static_assert(std::less<propagate_const<const int*>>{}(xx3, xx4), "");
static_assert(std::greater<propagate_const<const int*>>{}(xx4, xx3), "");
static_assert(std::less_equal<propagate_const<const int*>>{}(xx3, xx4), "");
static_assert(std::greater_equal<propagate_const<const int*>>{}(xx4, xx3), "");
static_assert(std::less_equal<propagate_const<const int*>>{}(xx3, xx3), "");
static_assert(std::greater_equal<propagate_const<const int*>>{}(xx4, xx4), "");
}

View File

@ -0,0 +1,37 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2013-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <memory>
using std::experimental::propagate_const;
using std::unique_ptr;
using std::shared_ptr;
propagate_const<int*> test1;
propagate_const<const int*> test2;
propagate_const<unique_ptr<int>> test3;
propagate_const<unique_ptr<const int>> test4;
propagate_const<const unique_ptr<int>> test5;
propagate_const<const unique_ptr<const int>> test6;
propagate_const<shared_ptr<int>> test7;
propagate_const<shared_ptr<const int>> test8;
propagate_const<const shared_ptr<int>> test9;
propagate_const<const shared_ptr<const int>> test10;

View File

@ -0,0 +1,30 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
using std::experimental::propagate_const;
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 104 }
// { dg-error "not a pointer-to-object type" "" { target *-*-* } 65 }
// { dg-error "forming pointer to reference type" "" { target *-*-* } 184 }
// { dg-error "forming pointer to reference type" "" { target *-*-* } 210 }
propagate_const<void*> test1;

View File

@ -0,0 +1,27 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
using std::experimental::propagate_const;
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 104 }
propagate_const<void (*)()> test1;

View File

@ -0,0 +1,29 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
using std::experimental::propagate_const;
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 104 }
// { dg-error "invalid type" "" { target *-*-* } 65 }
// { dg-error "uninitialized reference member" "" { target *-*-* } 111 }
propagate_const<int&> test1; // { dg-error "use of deleted function" }

View File

@ -0,0 +1,27 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
using std::experimental::propagate_const;
// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 104 }
propagate_const<int[1]> test1;

View File

@ -0,0 +1,37 @@
// { dg-options "-std=gnu++14" }
// { dg-do run }
// Copyright (C) 2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <testsuite_hooks.h>
using std::experimental::propagate_const;
int main()
{
int x{42};
int y{666};
propagate_const<int*> xx{&x};
propagate_const<int*> yy{&y};
VERIFY(*xx == 42);
VERIFY(*yy == 666);
swap(xx, yy);
VERIFY(*xx == 666);
VERIFY(*yy == 42);
}

View File

@ -0,0 +1,32 @@
// { dg-options "-std=gnu++14" }
// { dg-do compile }
// Copyright (C) 2014-2015 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a moved_to of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
#include <experimental/propagate_const>
#include <type_traits>
#include <stdexcept>
template <typename T>
using check1_t = std::experimental::fundamentals_v2::propagate_const<T>;
template <typename T>
using check2_t
= typename std::experimental::fundamentals_v2::propagate_const<T>::element_type;
static_assert(std::is_same<check2_t<int*>, int>::value,
"element_type must be based on the pointer");