From: Ville Voutilainen Date: Fri, 3 Jul 2015 14:08:37 +0000 (+0300) Subject: Implement std::experimental::fundamentals_v2::propagate_const. X-Git-Tag: releases/gcc-6.1.0~5946 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e37e6813d517379a4973ec2ca441c750b6289e4b;p=thirdparty%2Fgcc.git Implement std::experimental::fundamentals_v2::propagate_const. 2015-07-03 Ville Voutilainen 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 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index b5bc0419dc86..fdcfd6186f45 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,28 @@ +2015-07-03 Ville Voutilainen + + 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 * acinclude.m4 (GLIBCXX_DEFAULT_ABI): Change valid arguments for diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index 05be8ad1b84a..c0028dd324e1 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -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 \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index bab83b40018c..24246a655419 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -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 \ diff --git a/libstdc++-v3/include/experimental/propagate_const b/libstdc++-v3/include/experimental/propagate_const new file mode 100644 index 000000000000..f90395964f77 --- /dev/null +++ b/libstdc++-v3/include/experimental/propagate_const @@ -0,0 +1,535 @@ +// -*- 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 +// . + +/** @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 +#else + +#include +#include + +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 + class propagate_const + { + public: + typedef remove_reference_t())> element_type; + + private: + template + struct __is_propagate_const : false_type + { }; + + template + struct __is_propagate_const> : true_type + { }; + + template + friend constexpr const _Up& + get_underlying(const propagate_const<_Up>& __pt) noexcept; + template + friend constexpr _Up& + get_underlying(propagate_const<_Up>& __pt) noexcept; + + template + static constexpr element_type* + __to_raw_pointer(_Up* __u) + { return __u; } + + template + static constexpr element_type* + __to_raw_pointer(_Up& __u) + { return __u.get(); } + + template + static constexpr const element_type* + __to_raw_pointer(const _Up* __u) + { return __u; } + + template + static constexpr const element_type* + __to_raw_pointer(const _Up& __u) + { return __u.get(); } + + public: + static_assert(__and_::type>, + __not_>, + __or_, 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 , + is_convertible<_Up&&, _Tp>>::value, bool + >::type=true> + constexpr propagate_const(propagate_const<_Up>&& __pu) + : __t(move(get_underlying(__pu))) + {} + template , + __not_>>::value, + bool>::type=false> + constexpr explicit propagate_const(propagate_const<_Up>&& __pu) + : __t(move(get_underlying(__pu))) + {} + template , + 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 , + __not_>, + __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 ::value>::type> + constexpr propagate_const& operator=(propagate_const<_Up>&& __pu) + { + __t = move(get_underlying(__pu)); + } + + template , + __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 , + 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 , + 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 + constexpr bool + operator==(const propagate_const<_Tp>& __pt, nullptr_t) + { + return get_underlying(__pt) == nullptr; + } + + template + constexpr bool + operator==(nullptr_t, const propagate_const<_Tp>& __pu) + { + return nullptr == get_underlying(__pu); + } + + template + constexpr bool + operator!=(const propagate_const<_Tp>& __pt, nullptr_t) + { + return get_underlying(__pt) != nullptr; + } + + template + constexpr bool operator!=(nullptr_t, const propagate_const<_Tp>& __pu) + { + return nullptr != get_underlying(__pu); + } + + template + constexpr bool + operator==(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) + { + return get_underlying(__pt) == get_underlying(__pu); + } + + template + constexpr bool + operator!=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) + { + return get_underlying(__pt) != get_underlying(__pu); + } + + template + constexpr bool + operator<(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) + { + return get_underlying(__pt) < get_underlying(__pu); + } + + template + constexpr bool + operator>(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) + { + return get_underlying(__pt) > get_underlying(__pu); + } + + template + constexpr bool + operator<=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) + { + return get_underlying(__pt) <= get_underlying(__pu); + } + + template + constexpr bool + operator>=(const propagate_const<_Tp>& __pt, + const propagate_const<_Up>& __pu) + { + return get_underlying(__pt) >= get_underlying(__pu); + } + + template + constexpr bool + operator==(const propagate_const<_Tp>& __pt, const _Up& __u) + { + return get_underlying(__pt) == __u; + } + + template + constexpr bool + operator!=(const propagate_const<_Tp>& __pt, const _Up& __u) + { + return get_underlying(__pt) != __u; + } + + template + constexpr bool + operator<(const propagate_const<_Tp>& __pt, const _Up& __u) + { + return get_underlying(__pt) < __u; + } + + template + constexpr bool + operator>(const propagate_const<_Tp>& __pt, const _Up& __u) + { + return get_underlying(__pt) > __u; + } + + template + constexpr bool + operator<=(const propagate_const<_Tp>& __pt, const _Up& __u) + { + return get_underlying(__pt) <= __u; + } + + template + constexpr bool + operator>=(const propagate_const<_Tp>& __pt, const _Up& __u) + { + return get_underlying(__pt) >= __u; + } + + template + constexpr bool + operator==(const _Tp& __t, const propagate_const<_Up>& __pu) + { + return __t == get_underlying(__pu); + } + + template + constexpr bool + operator!=(const _Tp& __t, const propagate_const<_Up>& __pu) + { + return __t != get_underlying(__pu); + } + + template + constexpr bool + operator<(const _Tp& __t, const propagate_const<_Up>& __pu) + { + return __t < get_underlying(__pu); + } + + template + constexpr bool + operator>(const _Tp& __t, const propagate_const<_Up>& __pu) + { + return __t > get_underlying(__pu); + } + + template + constexpr bool + operator<=(const _Tp& __t, const propagate_const<_Up>& __pu) + { + return __t <= get_underlying(__pu); + } + + template + constexpr bool + operator>=(const _Tp& __t, const propagate_const<_Up>& __pu) + { + return __t >= get_underlying(__pu); + } + + // [propagate_const.algorithms], specialized algorithms + template + 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 + constexpr const _Tp& + get_underlying(const propagate_const<_Tp>& __pt) noexcept + { + return __pt.__t; + } + + template + 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 + struct hash> + { + 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 + struct equal_to> + { + 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 + struct not_equal_to> + { + 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 + struct less> + { + 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 + struct greater> + { + 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 + struct less_equal> + { + 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 + struct greater_equal> + { + 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 diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/assignment/copy.cc b/libstdc++-v3/testsuite/experimental/propagate_const/assignment/copy.cc new file mode 100644 index 000000000000..eb88ee1754f4 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/assignment/copy.cc @@ -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 +// . + +#include + +using std::experimental::propagate_const; + +int main() +{ + int dummy; + propagate_const test1; + propagate_const test2; + test2 = test1; // { dg-error "deleted" } + test2 = &dummy; +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/assignment/move.cc b/libstdc++-v3/testsuite/experimental/propagate_const/assignment/move.cc new file mode 100644 index 000000000000..73843c54f1f1 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/assignment/move.cc @@ -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 +// . + +#include +#include +#include +#include + +using std::experimental::propagate_const; +using std::unique_ptr; + +int main() +{ + const int dummy{42}; + propagate_const test1; + test1 = std::move(&dummy); + test1 = &dummy; + VERIFY(test1.get() == &dummy); + propagate_const test2; + test2 = std::move(test1); + VERIFY(test1.get() == &dummy); + VERIFY(test2.get() == &dummy); + propagate_const test3; + test3 = std::move(test2); + VERIFY(test1.get() == &dummy); + VERIFY(test2.get() == &dummy); + VERIFY(test3.get() == &dummy); + propagate_const> test4; + test4 = std::make_unique(666); +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/assignment/move_neg.cc b/libstdc++-v3/testsuite/experimental/propagate_const/assignment/move_neg.cc new file mode 100644 index 000000000000..cb553e2ed5a1 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/assignment/move_neg.cc @@ -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 +// . + +#include +#include +#include +#include + +using std::experimental::propagate_const; +using std::unique_ptr; + +// { dg-error "no type" "" { target *-*-* } 158 } + +int main() +{ + propagate_const> test5; + test5 = new int{666}; // { dg-error "no match" } + const int* dummy2 = new int{666}; + propagate_const> test6; + test6 = dummy2; // { dg-error "no match" } +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/cons/copy.cc b/libstdc++-v3/testsuite/experimental/propagate_const/cons/copy.cc new file mode 100644 index 000000000000..6f7d99e368ed --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/cons/copy.cc @@ -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 +// . + +#include + +using std::experimental::propagate_const; + +int main() +{ + propagate_const test1; + propagate_const test2{test1}; // { dg-error "deleted" } + propagate_const test3 = test1; // { dg-error "deleted" } +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/cons/default.cc b/libstdc++-v3/testsuite/experimental/propagate_const/cons/default.cc new file mode 100644 index 000000000000..8106f694e328 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/cons/default.cc @@ -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 +// . + +#include +#include + +using std::experimental::propagate_const; + +int main() +{ + constexpr propagate_const test1{}; + static_assert(!test1.get(), ""); + propagate_const test2; + VERIFY(!test2.get()); +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/cons/move.cc b/libstdc++-v3/testsuite/experimental/propagate_const/cons/move.cc new file mode 100644 index 000000000000..38f495a86c88 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/cons/move.cc @@ -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 +// . + +#include +#include +#include +#include + +using std::experimental::propagate_const; +using std::unique_ptr; + +int main() +{ + const int dummy{42}; + propagate_const test1{&dummy}; + VERIFY(test1.get() == &dummy); + propagate_const test2{std::move(test1)}; + VERIFY(test1.get() == &dummy); + VERIFY(test2.get() == &dummy); + propagate_const test3{std::move(test2)}; + VERIFY(test1.get() == &dummy); + VERIFY(test2.get() == &dummy); + VERIFY(test3.get() == &dummy); + propagate_const> test4{std::make_unique(666)}; + propagate_const> test5{new int{666}}; + const int* dummy2 = new int{666}; + propagate_const> test6{dummy2}; +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/cons/move_neg.cc b/libstdc++-v3/testsuite/experimental/propagate_const/cons/move_neg.cc new file mode 100644 index 000000000000..caf084ddc046 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/cons/move_neg.cc @@ -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 +// . + +#include +#include +#include +#include + +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 test1{&dummy}; + propagate_const test2{&dummy}; // { dg-error "no matching function" } + propagate_const test3{std::move(test1)}; // { dg-error "no matching function" } + propagate_const> test4 = &dummy; // { dg-error "conversion" } + propagate_const> test5 = std::move(test1); // { dg-error "conversion" } +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/hash/1.cc b/libstdc++-v3/testsuite/experimental/propagate_const/hash/1.cc new file mode 100644 index 000000000000..41ebd2096ec3 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/hash/1.cc @@ -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 +// . + +#include +#include + +using std::experimental::propagate_const; +using std::hash; + +int main() +{ + int x{42}; + int y{666}; + propagate_const xx{&x}; + propagate_const yy{&y}; + VERIFY(hash{}(&x) == hash>{}(xx)); + VERIFY(hash{}(&y) == hash>{}(yy)); +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/observers/1.cc b/libstdc++-v3/testsuite/experimental/propagate_const/observers/1.cc new file mode 100644 index 000000000000..368b66037726 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/observers/1.cc @@ -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 +// . + +#include +#include + +using std::experimental::propagate_const; +using std::hash; + +int main() +{ + int x{42}; + propagate_const xx{&x}; + VERIFY(bool(xx)); + propagate_const xx2{}; + VERIFY(!bool(xx2)); + struct X {int x;}; + X x3{42}; + propagate_const xx3{&x3}; + VERIFY(xx3->x == 42); + VERIFY((*xx3).x == 42); + VERIFY(xx3.get() == &x3); + const propagate_const xx4{&x3}; + VERIFY(xx4->x == 42); + VERIFY((*xx4).x == 42); + VERIFY(xx4.get() == &x3); + static constexpr int x4{42}; + constexpr propagate_const xx5{&x4}; + static_assert(bool(xx5), ""); + constexpr propagate_const xx6{}; + static_assert(!bool(xx6), ""); + struct X2 {int x;}; + static constexpr X2 x5{42}; + constexpr propagate_const 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 xx9{&xx8}; + const propagate_const xx10{&xx8}; + VERIFY(xx9->f() == 42); + VERIFY(xx10->f() == 666); +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/relops/1.cc b/libstdc++-v3/testsuite/experimental/propagate_const/relops/1.cc new file mode 100644 index 000000000000..eff5df2079d2 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/relops/1.cc @@ -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 +// . + +#include +#include + +using std::experimental::propagate_const; +using std::hash; + +int main() +{ + int x[2]; + propagate_const xx1{&x[0]}; + propagate_const 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>{}(xx1, xx1)); + VERIFY(std::not_equal_to>{}(xx1, xx2)); + VERIFY(std::less>{}(xx1, xx2)); + VERIFY(std::greater>{}(xx2, xx1)); + VERIFY(std::less_equal>{}(xx1, xx2)); + VERIFY(std::greater_equal>{}(xx2, xx1)); + VERIFY(std::less_equal>{}(xx1, xx1)); + VERIFY(std::greater_equal>{}(xx2, xx2)); + static constexpr int x2[2]{}; + constexpr propagate_const xx3{&x2[0]}; + constexpr propagate_const 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>{}(xx3, xx3), ""); + static_assert(std::not_equal_to>{}(xx3, xx4), ""); + static_assert(std::less>{}(xx3, xx4), ""); + static_assert(std::greater>{}(xx4, xx3), ""); + static_assert(std::less_equal>{}(xx3, xx4), ""); + static_assert(std::greater_equal>{}(xx4, xx3), ""); + static_assert(std::less_equal>{}(xx3, xx3), ""); + static_assert(std::greater_equal>{}(xx4, xx4), ""); +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/requirements1.cc b/libstdc++-v3/testsuite/experimental/propagate_const/requirements1.cc new file mode 100644 index 000000000000..29423e87ce42 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/requirements1.cc @@ -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 +// . + +#include +#include + +using std::experimental::propagate_const; +using std::unique_ptr; +using std::shared_ptr; + +propagate_const test1; +propagate_const test2; +propagate_const> test3; +propagate_const> test4; +propagate_const> test5; +propagate_const> test6; +propagate_const> test7; +propagate_const> test8; +propagate_const> test9; +propagate_const> test10; diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/requirements2.cc b/libstdc++-v3/testsuite/experimental/propagate_const/requirements2.cc new file mode 100644 index 000000000000..5f75a311fd37 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/requirements2.cc @@ -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 +// . + +#include + +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 test1; diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/requirements3.cc b/libstdc++-v3/testsuite/experimental/propagate_const/requirements3.cc new file mode 100644 index 000000000000..71d6a32c190e --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/requirements3.cc @@ -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 +// . + +#include + +using std::experimental::propagate_const; + +// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 104 } + +propagate_const test1; diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/requirements4.cc b/libstdc++-v3/testsuite/experimental/propagate_const/requirements4.cc new file mode 100644 index 000000000000..942b176bd204 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/requirements4.cc @@ -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 +// . + +#include + +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 test1; // { dg-error "use of deleted function" } diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/requirements5.cc b/libstdc++-v3/testsuite/experimental/propagate_const/requirements5.cc new file mode 100644 index 000000000000..da023864f38e --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/requirements5.cc @@ -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 +// . + +#include + +using std::experimental::propagate_const; + +// { dg-error "requires a class or a pointer to an object type" "" { target *-*-* } 104 } + +propagate_const test1; diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/swap/1.cc b/libstdc++-v3/testsuite/experimental/propagate_const/swap/1.cc new file mode 100644 index 000000000000..a49b283be01b --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/swap/1.cc @@ -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 +// . + +#include +#include + +using std::experimental::propagate_const; + +int main() +{ + int x{42}; + int y{666}; + propagate_const xx{&x}; + propagate_const yy{&y}; + VERIFY(*xx == 42); + VERIFY(*yy == 666); + swap(xx, yy); + VERIFY(*xx == 666); + VERIFY(*yy == 42); +} diff --git a/libstdc++-v3/testsuite/experimental/propagate_const/typedefs.cc b/libstdc++-v3/testsuite/experimental/propagate_const/typedefs.cc new file mode 100644 index 000000000000..d9362c857ea3 --- /dev/null +++ b/libstdc++-v3/testsuite/experimental/propagate_const/typedefs.cc @@ -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 +// . + +#include +#include +#include + +template +using check1_t = std::experimental::fundamentals_v2::propagate_const; +template +using check2_t += typename std::experimental::fundamentals_v2::propagate_const::element_type; + +static_assert(std::is_same, int>::value, + "element_type must be based on the pointer");