From patchwork Fri Nov 19 20:25:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 47956 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3579F385C40B for ; Fri, 19 Nov 2021 20:27:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3579F385C40B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1637353651; bh=f+H7tKstyVtqmbnweFYrvz57R5JNCy+mPTTYYndVMH4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=OaKbQX6MokoYRTATLV9ZOS+i6EkFS99rROpuAFnRuphj+IGu+a+UJyaP0SJsRx5ta 7F7RLlH197UYsnmDeaj8zgBjCSHtW7IVZHwUN96SngPuTfWDfqHVnWyCyBFXlAOFyZ 7f7kpTSkyeY787Av7mZvH1QrwKgm8IMPLPHtDPdA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4FA79385BF9F for ; Fri, 19 Nov 2021 20:25:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4FA79385BF9F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-249-w2nqebVwNu2sKcXuiM1Gjg-1; Fri, 19 Nov 2021 15:25:12 -0500 X-MC-Unique: w2nqebVwNu2sKcXuiM1Gjg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3836610144E0; Fri, 19 Nov 2021 20:25:11 +0000 (UTC) Received: from localhost (unknown [10.33.36.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id 93E6460BF1; Fri, 19 Nov 2021 20:25:10 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Improve tests for stringstream constructors in C++20 Date: Fri, 19 Nov 2021 20:25:09 +0000 Message-Id: <20211119202509.502181-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=unavailable autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-linux, pushed to trunk. This ensures all constructors are checked. libstdc++-v3/ChangeLog: * testsuite/27_io/basic_istringstream/cons/char/1.cc: Check all constructors. * testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_ostringstream/cons/char/1.cc: Likewise. * testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc: Likewise. * testsuite/27_io/basic_stringstream/cons/char/1.cc: Likewise. * testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc: Likewise. --- .../27_io/basic_istringstream/cons/char/1.cc | 119 +++++++++++++++-- .../basic_istringstream/cons/wchar_t/1.cc | 119 +++++++++++++++-- .../27_io/basic_ostringstream/cons/char/1.cc | 121 ++++++++++++++--- .../basic_ostringstream/cons/wchar_t/1.cc | 122 +++++++++++++++--- .../27_io/basic_stringstream/cons/char/1.cc | 121 ++++++++++++++--- .../basic_stringstream/cons/wchar_t/1.cc | 119 +++++++++++++++-- 6 files changed, 633 insertions(+), 88 deletions(-) diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc index bfd56b98dff..a3c736eba0c 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/char/1.cc @@ -15,7 +15,7 @@ // with this library; see the file COPYING3. If not see // . -// C++20 29.8.2.2 basic_stringbuf constructors [stringbuf.cons +// C++20 29.8.3.2 basic_istringstream constructors [istringstream.cons] // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } @@ -49,29 +49,120 @@ test02() void test03() { - using alloc_type = __gnu_test::tracker_allocator; - using str_type = std::basic_string, alloc_type>; + using C = char; + using alloc_type = __gnu_test::uneq_allocator; + using traits_type = std::char_traits; + using string = std::basic_string; + using istringstream = std::basic_istringstream; auto const mode = std::ios_base::in; - str_type s1(cstr); + alloc_type a1(1); + const string s1(cstr, a1); + // basic_istringstream() { - std::istringstream::allocator_type a; - std::istringstream sbuf(s1, mode, a); - std::string s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + istringstream ss; + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_istringstream(openmode) { - std::istringstream sbuf(s1, mode); - std::string s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + istringstream ss(mode); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_istringstream(const basic_string&, openmode = in) { - std::istringstream sbuf(s1); - std::string s2(cstr); - VERIFY( sbuf.str() == s2 ); + istringstream ss(s1); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(const basic_string&, openmode = in) + { + istringstream ss(s1, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(openmode, const A&) + { + istringstream ss(mode, a1); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(basic_string&&, openmode = in) + { + istringstream ss(string{s1}); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(basic_string&&, openmode = in) + { + istringstream ss(string(s1), mode); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(const basic_string&, const A&) + { + alloc_type a2(2); + istringstream ss(s1, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_istringstream(const basic_string&, const A&) + { + alloc_type a2(2); + const std::string s2 = cstr; + istringstream ss(s2, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_istringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + istringstream ss(s1, mode, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_istringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + const std::string s2 = cstr; + istringstream ss(s2, mode, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_istringstream(const basic_string&, openmode = in) + { + alloc_type a0; + const std::string s2 = cstr; + istringstream ss(s2, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } } diff --git a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc index 5573a72311d..a3c1afe6aa2 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istringstream/cons/wchar_t/1.cc @@ -15,7 +15,7 @@ // with this library; see the file COPYING3. If not see // . -// C++20 29.8.2.2 basic_stringbuf constructors [stringbuf.cons +// C++20 29.8.3.2 basic_istringstream constructors [istringstream.cons] // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } @@ -49,29 +49,120 @@ test02() void test03() { - using alloc_type = __gnu_test::tracker_allocator; - using str_type = std::basic_string, alloc_type>; + using C = wchar_t; + using alloc_type = __gnu_test::uneq_allocator; + using traits_type = std::char_traits; + using string = std::basic_string; + using istringstream = std::basic_istringstream; auto const mode = std::ios_base::in; - str_type s1(cstr); + alloc_type a1(1); + const string s1(cstr, a1); + // basic_istringstream() { - std::wistringstream::allocator_type a; - std::wistringstream sbuf(s1, mode, a); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + istringstream ss; + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_istringstream(openmode) { - std::wistringstream sbuf(s1, mode); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + istringstream ss(mode); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_istringstream(const basic_string&, openmode = in) { - std::wistringstream sbuf(s1); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + istringstream ss(s1); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(const basic_string&, openmode = in) + { + istringstream ss(s1, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(openmode, const A&) + { + istringstream ss(mode, a1); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(basic_string&&, openmode = in) + { + istringstream ss(string{s1}); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(basic_string&&, openmode = in) + { + istringstream ss(string(s1), mode); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_istringstream(const basic_string&, const A&) + { + alloc_type a2(2); + istringstream ss(s1, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_istringstream(const basic_string&, const A&) + { + alloc_type a2(2); + const std::wstring s2 = cstr; + istringstream ss(s2, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_istringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + istringstream ss(s1, mode, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_istringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + const std::wstring s2 = cstr; + istringstream ss(s2, mode, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_istringstream(const basic_string&, openmode = in) + { + alloc_type a0; + const std::wstring s2 = cstr; + istringstream ss(s2, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } } diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc index 93d35756a74..a337916441e 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/char/1.cc @@ -15,7 +15,7 @@ // with this library; see the file COPYING3. If not see // . -// C++20 29.8.2.2 basic_stringbuf constructors [stringbuf.cons +// C++20 29.8.4.2 basic_ostringstream constructors [ostringstream.cons] // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } @@ -49,29 +49,120 @@ test02() void test03() { - using alloc_type = __gnu_test::tracker_allocator; - using str_type = std::basic_string, alloc_type>; + using C = char; + using alloc_type = __gnu_test::uneq_allocator; + using traits_type = std::char_traits; + using string = std::basic_string; + using ostringstream = std::basic_ostringstream; - auto const mode = std::ios_base::out; - str_type s1(cstr); + auto const mode = std::ios_base::in; + alloc_type a1(1); + const string s1(cstr, a1); + // basic_ostringstream() { - std::ostringstream::allocator_type a; - std::ostringstream sbuf(s1, mode, a); - std::string s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + ostringstream ss; + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_ostringstream(openmode) { - std::ostringstream sbuf(s1, mode); - std::string s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + ostringstream ss(mode); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_ostringstream(const basic_string&, openmode = in) { - std::ostringstream sbuf(s1); - std::string s2(cstr); - VERIFY( sbuf.str() == s2 ); + ostringstream ss(s1); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(const basic_string&, openmode = in) + { + ostringstream ss(s1, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(openmode, const A&) + { + ostringstream ss(mode, a1); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(basic_string&&, openmode = in) + { + ostringstream ss(string{s1}); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(basic_string&&, openmode = in) + { + ostringstream ss(string(s1), mode); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(const basic_string&, const A&) + { + alloc_type a2(2); + ostringstream ss(s1, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_ostringstream(const basic_string&, const A&) + { + alloc_type a2(2); + const std::string s2 = cstr; + ostringstream ss(s2, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_ostringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + ostringstream ss(s1, mode, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_ostringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + const std::string s2 = cstr; + ostringstream ss(s2, mode, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_ostringstream(const basic_string&, openmode = in) + { + alloc_type a0; + const std::string s2 = cstr; + ostringstream ss(s2, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } } diff --git a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc index 12767c781d7..12e40a79740 100644 --- a/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_ostringstream/cons/wchar_t/1.cc @@ -15,7 +15,7 @@ // with this library; see the file COPYING3. If not see // . -// C++20 29.8.2.2 basic_stringbuf constructors [stringbuf.cons +// C++20 29.8.4.2 basic_ostringstream constructors [ostringstream.cons] // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } @@ -49,32 +49,122 @@ test02() void test03() { - using alloc_type = __gnu_test::tracker_allocator; - using str_type = std::basic_string, alloc_type>; + using C = wchar_t; + using alloc_type = __gnu_test::uneq_allocator; + using traits_type = std::char_traits; + using string = std::basic_string; + using ostringstream = std::basic_ostringstream; - auto const mode = std::ios_base::out; - str_type s1(cstr); + auto const mode = std::ios_base::in; + alloc_type a1(1); + const string s1(cstr, a1); + // basic_ostringstream() { - std::wostringstream::allocator_type a; - std::wostringstream sbuf(s1, mode, a); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + ostringstream ss; + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_ostringstream(openmode) { - std::wostringstream sbuf(s1, mode); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + ostringstream ss(mode); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_ostringstream(const basic_string&, openmode = in) { - std::wostringstream sbuf(s1); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + ostringstream ss(s1); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(const basic_string&, openmode = in) + { + ostringstream ss(s1, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(openmode, const A&) + { + ostringstream ss(mode, a1); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(basic_string&&, openmode = in) + { + ostringstream ss(string{s1}); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(basic_string&&, openmode = in) + { + ostringstream ss(string(s1), mode); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_ostringstream(const basic_string&, const A&) + { + alloc_type a2(2); + ostringstream ss(s1, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_ostringstream(const basic_string&, const A&) + { + alloc_type a2(2); + const std::wstring s2 = cstr; + ostringstream ss(s2, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_ostringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + ostringstream ss(s1, mode, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_ostringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + const std::wstring s2 = cstr; + ostringstream ss(s2, mode, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_ostringstream(const basic_string&, openmode = in) + { + alloc_type a0; + const std::wstring s2 = cstr; + ostringstream ss(s2, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } } - int main() { diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc index 7cb9f34ca04..6395ae3e242 100644 --- a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/char/1.cc @@ -15,7 +15,7 @@ // with this library; see the file COPYING3. If not see // . -// C++20 29.8.2.2 basic_stringbuf constructors [stringbuf.cons +// C++20 29.8.5.2 basic_stringstream constructors [stringstream.cons] // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } @@ -49,29 +49,120 @@ test02() void test03() { - using alloc_type = __gnu_test::tracker_allocator; - using str_type = std::basic_string, alloc_type>; + using C = char; + using alloc_type = __gnu_test::uneq_allocator; + using traits_type = std::char_traits; + using string = std::basic_string; + using stringstream = std::basic_stringstream; - auto const mode = std::ios_base::in | std::ios_base::out; - str_type s1(cstr); + auto const mode = std::ios_base::in; + alloc_type a1(1); + const string s1(cstr, a1); + // basic_stringstream() { - std::stringstream::allocator_type a; - std::stringstream ss(s1, mode, a); - std::string s2(cstr); - VERIFY( ss.str() == s2 ); + alloc_type a0; + stringstream ss; + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_stringstream(openmode) { - std::stringstream ss(s1, mode); - std::string s2(cstr); - VERIFY( ss.str() == s2 ); + alloc_type a0; + stringstream ss(mode); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_stringstream(const basic_string&, openmode = in) { - std::stringstream ss(s1); - std::string s2(cstr); - VERIFY( ss.str() == s2 ); + stringstream ss(s1); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(const basic_string&, openmode = in) + { + stringstream ss(s1, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(openmode, const A&) + { + stringstream ss(mode, a1); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(basic_string&&, openmode = in) + { + stringstream ss(string{s1}); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(basic_string&&, openmode = in) + { + stringstream ss(string(s1), mode); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(const basic_string&, const A&) + { + alloc_type a2(2); + stringstream ss(s1, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_stringstream(const basic_string&, const A&) + { + alloc_type a2(2); + const std::string s2 = cstr; + stringstream ss(s2, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_stringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + stringstream ss(s1, mode, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_stringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + const std::string s2 = cstr; + stringstream ss(s2, mode, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_stringstream(const basic_string&, openmode = in) + { + alloc_type a0; + const std::string s2 = cstr; + stringstream ss(s2, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } } diff --git a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc index 5573a72311d..d4c412276cc 100644 --- a/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc +++ b/libstdc++-v3/testsuite/27_io/basic_stringstream/cons/wchar_t/1.cc @@ -15,7 +15,7 @@ // with this library; see the file COPYING3. If not see // . -// C++20 29.8.2.2 basic_stringbuf constructors [stringbuf.cons +// C++20 29.8.5.2 basic_stringstream constructors [stringstream.cons] // { dg-options "-std=gnu++2a" } // { dg-do run { target c++2a } } @@ -49,29 +49,120 @@ test02() void test03() { - using alloc_type = __gnu_test::tracker_allocator; - using str_type = std::basic_string, alloc_type>; + using C = wchar_t; + using alloc_type = __gnu_test::uneq_allocator; + using traits_type = std::char_traits; + using string = std::basic_string; + using stringstream = std::basic_stringstream; auto const mode = std::ios_base::in; - str_type s1(cstr); + alloc_type a1(1); + const string s1(cstr, a1); + // basic_stringstream() { - std::wistringstream::allocator_type a; - std::wistringstream sbuf(s1, mode, a); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + stringstream ss; + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_stringstream(openmode) { - std::wistringstream sbuf(s1, mode); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + alloc_type a0; + stringstream ss(mode); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } + // basic_stringstream(const basic_string&, openmode = in) { - std::wistringstream sbuf(s1); - std::wstring s2(cstr); - VERIFY( sbuf.str() == s2 ); + stringstream ss(s1); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(const basic_string&, openmode = in) + { + stringstream ss(s1, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(openmode, const A&) + { + stringstream ss(mode, a1); + VERIFY( ss.str().empty() ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(basic_string&&, openmode = in) + { + stringstream ss(string{s1}); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(basic_string&&, openmode = in) + { + stringstream ss(string(s1), mode); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a1 ); + VERIFY( ss.str().get_allocator() == a1 ); + } + + // basic_stringstream(const basic_string&, const A&) + { + alloc_type a2(2); + stringstream ss(s1, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_stringstream(const basic_string&, const A&) + { + alloc_type a2(2); + const std::wstring s2 = cstr; + stringstream ss(s2, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_stringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + stringstream ss(s1, mode, a2); + VERIFY( ss.str() == s1 ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_stringstream(const basic_string&, openmode, const A&) + { + alloc_type a2(2); + const std::wstring s2 = cstr; + stringstream ss(s2, mode, a2); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a2 ); + VERIFY( ss.str().get_allocator() == a2 ); + } + + // basic_stringstream(const basic_string&, openmode = in) + { + alloc_type a0; + const std::wstring s2 = cstr; + stringstream ss(s2, mode); + VERIFY( ss.str() == cstr ); + VERIFY( ss.rdbuf()->get_allocator() == a0 ); + VERIFY( ss.str().get_allocator() == a0 ); } }