public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] 21_strings/basic_string/capacity/wchar_t/18654.cc
@ 2015-11-13 18:41 David Edelsohn
  2015-11-13 23:53 ` David Edelsohn
  0 siblings, 1 reply; 4+ messages in thread
From: David Edelsohn @ 2015-11-13 18:41 UTC (permalink / raw)
  To: Jonathan Wakely, Paolo Carlini; +Cc: GCC Patches

http://www.cplusplus.com/reference/string/basic_string/reserve/

"Note that the resulting string capacity may be equal or greater than n."

The current testcase verifies that the capacity is exactly equal to
the length of the string or reserve value, but the standard allows the
capacity to be larger.  On AIX, the capacity is larger and the
testcase incorrectly fails.

Linux x86-64:
i: 4
str.length: 4
str.capacity: 4
str.capacity: 12
str.capacity: 8
str.capacity: 4

AIX:
i: 4
str.length: 4
str.capacity: 7   <-- i
str.capacity: 14  <-- i*3
str.capacity: 8   <-- i*2
str.capacity: 7   <-- default

* 21_strings/basic_string/capacity/wchar_t/18654.cc: Verify the
capacity is greater than or equal to the requested amount.

Index: 18654.cc
===================================================================
--- 18654.cc    (revision 230322)
+++ 18654.cc    (working copy)
@@ -50,10 +50,10 @@
       str.reserve(3 * i);

       str.reserve(2 * i);
-      VERIFY( str.capacity() == 2 * i );
+      VERIFY( str.capacity() >= 2 * i );

       str.reserve();
-      VERIFY( str.capacity() == i );
+      VERIFY( str.capacity() >= i );
     }
 }

Thanks, David

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

* Re: [PATCH] 21_strings/basic_string/capacity/wchar_t/18654.cc
  2015-11-13 18:41 [PATCH] 21_strings/basic_string/capacity/wchar_t/18654.cc David Edelsohn
@ 2015-11-13 23:53 ` David Edelsohn
  2015-11-14  0:56   ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: David Edelsohn @ 2015-11-13 23:53 UTC (permalink / raw)
  To: Jonathan Wakely, Paolo Carlini; +Cc: GCC Patches

On Fri, Nov 13, 2015 at 1:40 PM, David Edelsohn <dje.gcc@gmail.com> wrote:
> http://www.cplusplus.com/reference/string/basic_string/reserve/
>
> "Note that the resulting string capacity may be equal or greater than n."
>
> The current testcase verifies that the capacity is exactly equal to
> the length of the string or reserve value, but the standard allows the
> capacity to be larger.  On AIX, the capacity is larger and the
> testcase incorrectly fails.
>
> Linux x86-64:
> i: 4
> str.length: 4
> str.capacity: 4
> str.capacity: 12
> str.capacity: 8
> str.capacity: 4
>
> AIX:
> i: 4
> str.length: 4
> str.capacity: 7   <-- i
> str.capacity: 14  <-- i*3
> str.capacity: 8   <-- i*2
> str.capacity: 7   <-- default
>
> * 21_strings/basic_string/capacity/wchar_t/18654.cc: Verify the

Jonathan,

AIX has 2-byte wchar_t in 32 bit mode, which seems to be the cause of
all of the libstdc++ testsuite wchar_t failures.  If GCC libstdc++ is
suppose to shrink-to-fit, how should the testcases be fixed?

Thanks, David

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

* Re: [PATCH] 21_strings/basic_string/capacity/wchar_t/18654.cc
  2015-11-13 23:53 ` David Edelsohn
@ 2015-11-14  0:56   ` Jonathan Wakely
  2015-11-14 17:25     ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2015-11-14  0:56 UTC (permalink / raw)
  To: David Edelsohn; +Cc: Paolo Carlini, GCC Patches

On 13 November 2015 at 23:53, David Edelsohn <dje.gcc@gmail.com> wrote:
> On Fri, Nov 13, 2015 at 1:40 PM, David Edelsohn <dje.gcc@gmail.com> wrote:
>> http://www.cplusplus.com/reference/string/basic_string/reserve/
>>
>> "Note that the resulting string capacity may be equal or greater than n."
>>
>> The current testcase verifies that the capacity is exactly equal to
>> the length of the string or reserve value, but the standard allows the
>> capacity to be larger.  On AIX, the capacity is larger and the
>> testcase incorrectly fails.
>>
>> Linux x86-64:
>> i: 4
>> str.length: 4
>> str.capacity: 4
>> str.capacity: 12
>> str.capacity: 8
>> str.capacity: 4
>>
>> AIX:
>> i: 4
>> str.length: 4
>> str.capacity: 7   <-- i
>> str.capacity: 14  <-- i*3
>> str.capacity: 8   <-- i*2
>> str.capacity: 7   <-- default
>>
>> * 21_strings/basic_string/capacity/wchar_t/18654.cc: Verify the
>
> Jonathan,
>
> AIX has 2-byte wchar_t in 32 bit mode, which seems to be the cause of
> all of the libstdc++ testsuite wchar_t failures.  If GCC libstdc++ is
> suppose to shrink-to-fit, how should the testcases be fixed?

It's shrink-to-fit, but not below a minimum size, which depends on
sizeof(wchar_t).

Something like https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=63f5425911daddb9a328565cb0acc3b0f30144fa#patch81
would work for both old and new string ABIs, I'll prepare an
equivalent patch for the wchar_t test case.

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

* Re: [PATCH] 21_strings/basic_string/capacity/wchar_t/18654.cc
  2015-11-14  0:56   ` Jonathan Wakely
@ 2015-11-14 17:25     ` Jonathan Wakely
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2015-11-14 17:25 UTC (permalink / raw)
  To: David Edelsohn; +Cc: Paolo Carlini, GCC Patches, libstdc++

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

On 14 November 2015 at 00:56, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> On 13 November 2015 at 23:53, David Edelsohn <dje.gcc@gmail.com> wrote:
>> On Fri, Nov 13, 2015 at 1:40 PM, David Edelsohn <dje.gcc@gmail.com> wrote:
>>> http://www.cplusplus.com/reference/string/basic_string/reserve/
>>>
>>> "Note that the resulting string capacity may be equal or greater than n."
>>>
>>> The current testcase verifies that the capacity is exactly equal to
>>> the length of the string or reserve value, but the standard allows the
>>> capacity to be larger.  On AIX, the capacity is larger and the
>>> testcase incorrectly fails.
>>>
>>> Linux x86-64:
>>> i: 4
>>> str.length: 4
>>> str.capacity: 4
>>> str.capacity: 12
>>> str.capacity: 8
>>> str.capacity: 4
>>>
>>> AIX:
>>> i: 4
>>> str.length: 4
>>> str.capacity: 7   <-- i
>>> str.capacity: 14  <-- i*3
>>> str.capacity: 8   <-- i*2
>>> str.capacity: 7   <-- default
>>>
>>> * 21_strings/basic_string/capacity/wchar_t/18654.cc: Verify the
>>
>> Jonathan,
>>
>> AIX has 2-byte wchar_t in 32 bit mode, which seems to be the cause of
>> all of the libstdc++ testsuite wchar_t failures.  If GCC libstdc++ is
>> suppose to shrink-to-fit, how should the testcases be fixed?
>
> It's shrink-to-fit, but not below a minimum size, which depends on
> sizeof(wchar_t).
>
> Something like https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=63f5425911daddb9a328565cb0acc3b0f30144fa#patch81
> would work for both old and new string ABIs, I'll prepare an
> equivalent patch for the wchar_t test case.

This makes it adapt to the short-string buffer size, rather than
making an assumption about sizeof(wchar_t). Committed to trunk.

I'll have a look at the other wchar_t failures on AIX.

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

commit e907e5ca66e8a829eb5359c1b18e079ccd77f989
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Sat Nov 14 16:57:17 2015 +0000

    Fix std::wstring capacity test for short wchar_t
    
    	* testsuite/21_strings/basic_string/capacity/char/18654.cc: Use
    	real minimum capacity.
    	* testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc:
    	Likewise.

diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/18654.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/18654.cc
index 6944627..2198077 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/18654.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/char/18654.cc
@@ -38,7 +38,7 @@ void test01()
 
 #if _GLIBCXX_USE_CXX11_ABI
   // Can't shrink below small string size.
-  const size_type minsize = 2 << 3;
+  const size_type minsize = string().capacity() + 1;
 #else
   // Exact shrink-to-size and shrink-to-fit
   const size_type minsize = 2 << 0;
diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc
index 3bd853a..d6202c9 100644
--- a/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc
+++ b/libstdc++-v3/testsuite/21_strings/basic_string/capacity/wchar_t/18654.cc
@@ -38,7 +38,7 @@ void test01()
 
 #if _GLIBCXX_USE_CXX11_ABI
   // Can't shrink below small string size.
-  const size_type minsize = 2 << 1;
+  const size_type minsize = wstring().capacity() + 1;
 #else
   // Exact shrink-to-size and shrink-to-fit
   const size_type minsize = 2 << 0;

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

end of thread, other threads:[~2015-11-14 17:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-13 18:41 [PATCH] 21_strings/basic_string/capacity/wchar_t/18654.cc David Edelsohn
2015-11-13 23:53 ` David Edelsohn
2015-11-14  0:56   ` Jonathan Wakely
2015-11-14 17:25     ` Jonathan Wakely

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