From 1138a19dfe5029e6ead3bb26bb344bddce9f24f0 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Thu, 14 Feb 2019 14:10:12 +0000 Subject: [PATCH] Enforce LWG DR 2566 requirement for container adaptors Although there is no good use for stack> or similar types with a mismatched value_type, it's possible somebody is doing that and getting away with it currently. This patch only enforces the new requirement for C++17 and later. During stage 1 we should consider enforcing it for C++11 and C++14. * doc/xml/manual/intro.xml: Document LWG 2566 status. * include/bits/stl_queue.h (queue, priority_queue): Add static assertions to enforce LWG 2566 requirement on value_type. * include/bits/stl_stack.h (stack): Likewise. From-SVN: r268877 --- libstdc++-v3/ChangeLog | 5 +++++ libstdc++-v3/doc/xml/manual/intro.xml | 9 +++++++- libstdc++-v3/include/bits/stl_queue.h | 30 ++++++++++++++++++++------- libstdc++-v3/include/bits/stl_stack.h | 10 ++++++++- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index c20c4e1acd4..8cedc38c1a4 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,10 @@ 2019-02-14 Jonathan Wakely + * doc/xml/manual/intro.xml: Document LWG 2566 status. + * include/bits/stl_queue.h (queue, priority_queue): Add static + assertions to enforce LWG 2566 requirement on value_type. + * include/bits/stl_stack.h (stack): Likewise. + PR middle-end/89303 * testsuite/20_util/enable_shared_from_this/89303.cc: New test. diff --git a/libstdc++-v3/doc/xml/manual/intro.xml b/libstdc++-v3/doc/xml/manual/intro.xml index 71050a0cebc..2a3231f4eb4 100644 --- a/libstdc++-v3/doc/xml/manual/intro.xml +++ b/libstdc++-v3/doc/xml/manual/intro.xml @@ -1120,11 +1120,18 @@ requirements of the license of GCC. ill-formed. + 2537: + Requirements on the first template parameter of container adaptors + + + Add static assertions to enforce the requirement. + + 2583: There is no way to supply an allocator for basic_string(str, pos) - Add new constructor + Add new constructor. 2684: diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h index 6d092c9bbfe..1eb56810edc 100644 --- a/libstdc++-v3/include/bits/stl_queue.h +++ b/libstdc++-v3/include/bits/stl_queue.h @@ -118,7 +118,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using _Uses = typename enable_if::value>::type; -#endif + +#if __cplusplus >= 201703L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2566. Requirements on the first template parameter of container + // adaptors + static_assert(is_same<_Tp, typename _Sequence::value_type>::value, + "value_type must be the same as the underlying container"); +#endif // C++17 +#endif // C++11 public: typedef typename _Sequence::value_type value_type; @@ -451,17 +459,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using _Uses = typename enable_if::value>::type; -#endif + +#if __cplusplus >= 201703L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2566. Requirements on the first template parameter of container + // adaptors + static_assert(is_same<_Tp, typename _Sequence::value_type>::value, + "value_type must be the same as the underlying container"); +#endif // C++17 +#endif // C++11 public: typedef typename _Sequence::value_type value_type; - typedef typename _Sequence::reference reference; - typedef typename _Sequence::const_reference const_reference; - typedef typename _Sequence::size_type size_type; - typedef _Sequence container_type; + typedef typename _Sequence::reference reference; + typedef typename _Sequence::const_reference const_reference; + typedef typename _Sequence::size_type size_type; + typedef _Sequence container_type; // _GLIBCXX_RESOLVE_LIB_DEFECTS // DR 2684. priority_queue lacking comparator typedef - typedef _Compare value_compare; + typedef _Compare value_compare; protected: // See queue::c for notes on these names. diff --git a/libstdc++-v3/include/bits/stl_stack.h b/libstdc++-v3/include/bits/stl_stack.h index e8443a78a05..28faab2e871 100644 --- a/libstdc++-v3/include/bits/stl_stack.h +++ b/libstdc++-v3/include/bits/stl_stack.h @@ -120,7 +120,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using _Uses = typename enable_if::value>::type; -#endif + +#if __cplusplus >= 201703L + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 2566. Requirements on the first template parameter of container + // adaptors + static_assert(is_same<_Tp, typename _Sequence::value_type>::value, + "value_type must be the same as the underlying container"); +#endif // C++17 +#endif // C++11 public: typedef typename _Sequence::value_type value_type; -- 2.30.2