public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [committed] libstdc++: Fix CTAD for debug sequence containers
Date: Wed, 18 Aug 2021 15:36:48 +0100	[thread overview]
Message-ID: <YR0bAOC8SNKkciwE@redhat.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1231 bytes --]

This fixes some 23_containers/*/cons/deduction.cc failures seen with
-std=c++17/-D_GLIBCXX_DEBUG, caused by non-immediate errors when
substituting template arguments into an incorrect specialization of the
std::__cxx1998 base class. This happens because the size_type member of
the debug container is _Base_type::size_type, so is non-deducible, and
the deduced types get substituted into _Base_type, triggering the
static_assert that checks the allocator's value_type matches the
container's.

The solution is to make the C(size_type, const T&, const Alloc&)
constructors of the debug sequence containers non-deducible. In order to
make CTAD work again deduction guides that use std::size_t for the first
argument are added.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

libstdc++-v3/ChangeLog:

	* include/debug/deque (deque(size_type, const T&, const A&)):
	Prevent class template argument deduction and replace with a
	deduction guide.
	* include/debug/forward_list (forward_list(size_type, const T&, const A&)):
	Likewise.
	* include/debug/list (list(size_type, const T&, const A&)):
	Likewise.
	* include/debug/vector (vector(size_type, const T&, const A&)):
	Likewise.

Tested powerpc64le-linux. Committed to trunk.


[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 5487 bytes --]

commit 085c2f8f0e13d7c1515ce86755a52a31faf0cf47
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Aug 17 18:19:27 2021

    libstdc++: Fix CTAD for debug sequence containers
    
    This fixes some 23_containers/*/cons/deduction.cc failures seen with
    -std=c++17/-D_GLIBCXX_DEBUG, caused by non-immediate errors when
    substituting template arguments into an incorrect specialization of the
    std::__cxx1998 base class. This happens because the size_type member of
    the debug container is _Base_type::size_type, so is non-deducible, and
    the deduced types get substituted into _Base_type, triggering the
    static_assert that checks the allocator's value_type matches the
    container's.
    
    The solution is to make the C(size_type, const T&, const Alloc&)
    constructors of the debug sequence containers non-deducible. In order to
    make CTAD work again deduction guides that use std::size_t for the first
    argument are added.
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            * include/debug/deque (deque(size_type, const T&, const A&)):
            Prevent class template argument deduction and replace with a
            deduction guide.
            * include/debug/forward_list (forward_list(size_type, const T&, const A&)):
            Likewise.
            * include/debug/list (list(size_type, const T&, const A&)):
            Likewise.
            * include/debug/vector (vector(size_type, const T&, const A&)):
            Likewise.

diff --git a/libstdc++-v3/include/debug/deque b/libstdc++-v3/include/debug/deque
index 4257a1651bd..574cab11c6f 100644
--- a/libstdc++-v3/include/debug/deque
+++ b/libstdc++-v3/include/debug/deque
@@ -130,7 +130,7 @@ namespace __debug
       deque(size_type __n, const _Allocator& __a = _Allocator())
       : _Base(__n, __a) { }
 
-      deque(size_type __n, const _Tp& __value,
+      deque(size_type __n, const __type_identity_t<_Tp>& __value,
 	    const _Allocator& __a = _Allocator())
       : _Base(__n, __value, __a) { }
 #else
@@ -668,6 +668,11 @@ namespace __debug
 	   typename = _RequireAllocator<_Allocator>>
     deque(_InputIterator, _InputIterator, _Allocator = _Allocator())
       -> deque<_ValT, _Allocator>;
+
+  template<typename _Tp, typename _Allocator = allocator<_Tp>,
+	   typename = _RequireAllocator<_Allocator>>
+    deque(size_t, _Tp, _Allocator = _Allocator())
+      -> deque<_Tp, _Allocator>;
 #endif
 
   template<typename _Tp, typename _Alloc>
diff --git a/libstdc++-v3/include/debug/forward_list b/libstdc++-v3/include/debug/forward_list
index 9cc05e8129c..cae5b5f038b 100644
--- a/libstdc++-v3/include/debug/forward_list
+++ b/libstdc++-v3/include/debug/forward_list
@@ -251,7 +251,7 @@ namespace __debug
       : _Base(__n, __al)
       { }
 
-      forward_list(size_type __n, const _Tp& __value,
+      forward_list(size_type __n, const __type_identity_t<_Tp>& __value,
 		   const allocator_type& __al = allocator_type())
       : _Base(__n, __value, __al)
       { }
@@ -854,6 +854,11 @@ namespace __debug
 	   typename = _RequireAllocator<_Allocator>>
     forward_list(_InputIterator, _InputIterator, _Allocator = _Allocator())
       -> forward_list<_ValT, _Allocator>;
+
+  template<typename _Tp, typename _Allocator = allocator<_Tp>,
+	   typename = _RequireAllocator<_Allocator>>
+    forward_list(size_t, _Tp, _Allocator = _Allocator())
+      -> forward_list<_Tp, _Allocator>;
 #endif
 
   template<typename _Tp, typename _Alloc>
diff --git a/libstdc++-v3/include/debug/list b/libstdc++-v3/include/debug/list
index 83122f8248d..b599e93d147 100644
--- a/libstdc++-v3/include/debug/list
+++ b/libstdc++-v3/include/debug/list
@@ -135,7 +135,7 @@ namespace __debug
       list(size_type __n, const allocator_type& __a = allocator_type())
       : _Base(__n, __a) { }
 
-      list(size_type __n, const _Tp& __value,
+      list(size_type __n, const __type_identity_t<_Tp>& __value,
 	   const _Allocator& __a = _Allocator())
       : _Base(__n, __value, __a) { }
 #else
@@ -921,6 +921,11 @@ namespace __debug
 	   typename = _RequireAllocator<_Allocator>>
     list(_InputIterator, _InputIterator, _Allocator = _Allocator())
       -> list<_ValT, _Allocator>;
+
+  template<typename _Tp, typename _Allocator = allocator<_Tp>,
+	   typename = _RequireAllocator<_Allocator>>
+    list(size_t, _Tp, _Allocator = _Allocator())
+      -> list<_Tp, _Allocator>;
 #endif
 
   template<typename _Tp, typename _Alloc>
diff --git a/libstdc++-v3/include/debug/vector b/libstdc++-v3/include/debug/vector
index 55271384922..d30d750a6f0 100644
--- a/libstdc++-v3/include/debug/vector
+++ b/libstdc++-v3/include/debug/vector
@@ -181,7 +181,7 @@ namespace __debug
       vector(size_type __n, const _Allocator& __a = _Allocator())
       : _Base(__n, __a), _Safe_vector(__n) { }
 
-      vector(size_type __n, const _Tp& __value,
+      vector(size_type __n, const __type_identity_t<_Tp>& __value,
 	     const _Allocator& __a = _Allocator())
       : _Base(__n, __value, __a) { }
 #else
@@ -811,6 +811,11 @@ namespace __debug
 	   typename = _RequireAllocator<_Allocator>>
     vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
       -> vector<_ValT, _Allocator>;
+
+  template<typename _Tp, typename _Allocator = allocator<_Tp>,
+	   typename = _RequireAllocator<_Allocator>>
+    vector(size_t, _Tp, _Allocator = _Allocator())
+      -> vector<_Tp, _Allocator>;
 #endif
 
 } // namespace __debug

                 reply	other threads:[~2021-08-18 14:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YR0bAOC8SNKkciwE@redhat.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).