public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Remove _Safe_container _IsCxx11AllocatorAware template parameter
@ 2017-05-11 20:06 François Dumont
  2017-05-12 10:40 ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: François Dumont @ 2017-05-11 20:06 UTC (permalink / raw)
  To: libstdc++, gcc-patches

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

Hi

     _Safe_container _IsCxx11AllocatorAware template allocator is only 
used if C++11 Abi is not used so I simplified it.

     * include/debug/safe_container.h [_GLIBCXX_USE_CXX11_ABI]
     (_Safe_container<>): Remove _IsCxx11AllocatorAware template parameter.
     * include/debug/string: Adapt.

     Tested under Linux x86_64 with debug mode and active C++11 Abi.


François


[-- Attachment #2: safe_container.patch --]
[-- Type: text/x-patch, Size: 2532 bytes --]

diff --git a/libstdc++-v3/include/debug/safe_container.h b/libstdc++-v3/include/debug/safe_container.h
index 3d44c15..e985c2a 100644
--- a/libstdc++-v3/include/debug/safe_container.h
+++ b/libstdc++-v3/include/debug/safe_container.h
@@ -36,8 +36,12 @@ namespace __gnu_debug
   /// Safe class dealing with some allocator dependent operations.
   template<typename _SafeContainer,
 	   typename _Alloc,
-	   template<typename> class _SafeBase,
-	   bool _IsCxx11AllocatorAware = true>
+	   template<typename> class _SafeBase
+#if _GLIBCXX_USE_CXX11_ABI
+	   >
+#else
+	   , bool _IsCxx11AllocatorAware = true>
+#endif
     class _Safe_container
     : public _SafeBase<_SafeContainer>
     {
@@ -82,8 +86,10 @@ namespace __gnu_debug
       {
 	__glibcxx_check_self_move_assign(__x);
 
+#  if !_GLIBCXX_USE_CXX11_ABI
 	if (_IsCxx11AllocatorAware)
 	  {
+#  endif
 	    typedef __gnu_cxx::__alloc_traits<_Alloc> _Alloc_traits;
 
 	    bool __xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
@@ -92,9 +98,11 @@ namespace __gnu_debug
 	      _Base::_M_swap(__x);
 	    else
 	      this->_M_invalidate_all();
+#  if !_GLIBCXX_USE_CXX11_ABI
 	  }
 	else
 	  _Base::_M_swap(__x);
+#  endif
 
 	__x._M_invalidate_all();
 	return *this;
@@ -103,7 +111,9 @@ namespace __gnu_debug
       void
       _M_swap(_Safe_container& __x) noexcept
       {
+#  if !_GLIBCXX_USE_CXX11_ABI
 	if (_IsCxx11AllocatorAware)
+#  endif
 	  {
 	    typedef __gnu_cxx::__alloc_traits<_Alloc> _Alloc_traits;
 
diff --git a/libstdc++-v3/include/debug/string b/libstdc++-v3/include/debug/string
index 9d4057b..8fd292a 100644
--- a/libstdc++-v3/include/debug/string
+++ b/libstdc++-v3/include/debug/string
@@ -44,13 +44,20 @@ template<typename _CharT, typename _Traits = std::char_traits<_CharT>,
   class basic_string
   : public __gnu_debug::_Safe_container<
       basic_string<_CharT, _Traits, _Allocator>,
-      _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>,
+#if _GLIBCXX_USE_CXX11_ABI
+      _Allocator, _Safe_sequence>,
+#else
+      _Allocator, _Safe_sequence, false>,
+#endif
     public std::basic_string<_CharT, _Traits, _Allocator>
   {
     typedef std::basic_string<_CharT, _Traits, _Allocator>	_Base;
     typedef __gnu_debug::_Safe_container<
-      basic_string, _Allocator, _Safe_sequence, bool(_GLIBCXX_USE_CXX11_ABI)>
-      _Safe;
+#if _GLIBCXX_USE_CXX11_ABI
+      basic_string, _Allocator, _Safe_sequence> _Safe;
+#else
+      basic_string, _Allocator, _Safe_sequence, false> _Safe;
+#endif
 
   public:
     // types:


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Remove _Safe_container _IsCxx11AllocatorAware template parameter
  2017-05-11 20:06 Remove _Safe_container _IsCxx11AllocatorAware template parameter François Dumont
@ 2017-05-12 10:40 ` Jonathan Wakely
  2017-05-12 21:33   ` François Dumont
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2017-05-12 10:40 UTC (permalink / raw)
  To: François Dumont; +Cc: libstdc++, gcc-patches

On 11/05/17 22:03 +0200, François Dumont wrote:
>Hi
>
>    _Safe_container _IsCxx11AllocatorAware template allocator is only 
>used if C++11 Abi is not used so I simplified it.
>
>    * include/debug/safe_container.h [_GLIBCXX_USE_CXX11_ABI]
>    (_Safe_container<>): Remove _IsCxx11AllocatorAware template parameter.
>    * include/debug/string: Adapt.
>
>    Tested under Linux x86_64 with debug mode and active C++11 Abi.

Wait, doesn't this mean that debug containers have a different base
class depending on which ABI is active in the translation unit? That
is a One-Definition Rule violation when you link together objects
compiled with different values of _GLIBCXX_USE_CXX11_ABI, which is
supposed to work. I went to enormous effort to ensure it works.


>François
>

>diff --git a/libstdc++-v3/include/debug/safe_container.h b/libstdc++-v3/include/debug/safe_container.h
>index 3d44c15..e985c2a 100644
>--- a/libstdc++-v3/include/debug/safe_container.h
>+++ b/libstdc++-v3/include/debug/safe_container.h
>@@ -36,8 +36,12 @@ namespace __gnu_debug
>   /// Safe class dealing with some allocator dependent operations.
>   template<typename _SafeContainer,
> 	   typename _Alloc,
>-	   template<typename> class _SafeBase,
>-	   bool _IsCxx11AllocatorAware = true>
>+	   template<typename> class _SafeBase
>+#if _GLIBCXX_USE_CXX11_ABI
>+	   >
>+#else
>+	   , bool _IsCxx11AllocatorAware = true>
>+#endif
>     class _Safe_container

In any case, I don't think this is simpler, there are more lines of
code, and the preprocessor condition makes it harder to read and
harder to reason about.

>     : public _SafeBase<_SafeContainer>
>     {
>@@ -82,8 +86,10 @@ namespace __gnu_debug
>       {
> 	__glibcxx_check_self_move_assign(__x);
> 
>+#  if !_GLIBCXX_USE_CXX11_ABI
> 	if (_IsCxx11AllocatorAware)
> 	  {
>+#  endif

This is fairly pointless. Again it makes the code a bit harder to
read, and since it's a compile-time constant the condition will be
optimised away completely.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Remove _Safe_container _IsCxx11AllocatorAware template parameter
  2017-05-12 10:40 ` Jonathan Wakely
@ 2017-05-12 21:33   ` François Dumont
  0 siblings, 0 replies; 3+ messages in thread
From: François Dumont @ 2017-05-12 21:33 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches

On 12/05/2017 12:38, Jonathan Wakely wrote:
> On 11/05/17 22:03 +0200, François Dumont wrote:
>> Hi
>>
>>    _Safe_container _IsCxx11AllocatorAware template allocator is only 
>> used if C++11 Abi is not used so I simplified it.
>>
>>    * include/debug/safe_container.h [_GLIBCXX_USE_CXX11_ABI]
>>    (_Safe_container<>): Remove _IsCxx11AllocatorAware template 
>> parameter.
>>    * include/debug/string: Adapt.
>>
>>    Tested under Linux x86_64 with debug mode and active C++11 Abi.
>
> Wait, doesn't this mean that debug containers have a different base
> class depending on which ABI is active in the translation unit? That
> is a One-Definition Rule violation when you link together objects
> compiled with different values of _GLIBCXX_USE_CXX11_ABI, which is
> supposed to work. I went to enormous effort to ensure it works.
>
>
>> François
>>
>
>> diff --git a/libstdc++-v3/include/debug/safe_container.h 
>> b/libstdc++-v3/include/debug/safe_container.h
>> index 3d44c15..e985c2a 100644
>> --- a/libstdc++-v3/include/debug/safe_container.h
>> +++ b/libstdc++-v3/include/debug/safe_container.h
>> @@ -36,8 +36,12 @@ namespace __gnu_debug
>>   /// Safe class dealing with some allocator dependent operations.
>>   template<typename _SafeContainer,
>>        typename _Alloc,
>> -       template<typename> class _SafeBase,
>> -       bool _IsCxx11AllocatorAware = true>
>> +       template<typename> class _SafeBase
>> +#if _GLIBCXX_USE_CXX11_ABI
>> +       >
>> +#else
>> +       , bool _IsCxx11AllocatorAware = true>
>> +#endif
>>     class _Safe_container
>
> In any case, I don't think this is simpler, there are more lines of
> code, and the preprocessor condition makes it harder to read and
> harder to reason about.
>
>>     : public _SafeBase<_SafeContainer>
>>     {
>> @@ -82,8 +86,10 @@ namespace __gnu_debug
>>       {
>>     __glibcxx_check_self_move_assign(__x);
>>
>> +#  if !_GLIBCXX_USE_CXX11_ABI
>>     if (_IsCxx11AllocatorAware)
>>       {
>> +#  endif
>
> This is fairly pointless. Again it makes the code a bit harder to
> read, and since it's a compile-time constant the condition will be
> optimised away completely.
>
>
Ok, I reverted it.

François


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-12 21:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-11 20:06 Remove _Safe_container _IsCxx11AllocatorAware template parameter François Dumont
2017-05-12 10:40 ` Jonathan Wakely
2017-05-12 21:33   ` François Dumont

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).