libstdc++: testsuite: Simplify codecvt_unicode
Checks
Commit Message
Stop using unique_ptr, create some objects directly.
libstdc++-v3/ChangeLog:
* testsuite/22_locale/codecvt/codecvt_unicode.cc: Simplify.
* testsuite/22_locale/codecvt/codecvt_unicode.h: Simplify.
* testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc: Simplify.
---
.../22_locale/codecvt/codecvt_unicode.cc | 18 ++++++++++--------
.../22_locale/codecvt/codecvt_unicode.h | 9 +--------
.../codecvt/codecvt_unicode_wchar_t.cc | 12 ++++++------
3 files changed, 17 insertions(+), 22 deletions(-)
Comments
On Tue, 17 Jan 2023, 21:12 Dimitrij Mijoski via Libstdc++, <
libstdc++@gcc.gnu.org> wrote:
> Stop using unique_ptr, create some objects directly.
>
Thanks, I thought about suggesting this, but decided it was good enough.
But I'm glad to see the simplifications :-)
I'll get this committed.
> libstdc++-v3/ChangeLog:
>
> * testsuite/22_locale/codecvt/codecvt_unicode.cc: Simplify.
> * testsuite/22_locale/codecvt/codecvt_unicode.h: Simplify.
> * testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc: Simplify.
> ---
> .../22_locale/codecvt/codecvt_unicode.cc | 18 ++++++++++--------
> .../22_locale/codecvt/codecvt_unicode.h | 9 +--------
> .../codecvt/codecvt_unicode_wchar_t.cc | 12 ++++++------
> 3 files changed, 17 insertions(+), 22 deletions(-)
>
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.cc
> b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.cc
> index ae4b6c896..3d7393e4a 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.cc
> @@ -29,11 +29,12 @@ test_utf8_utf32_codecvts ()
> using codecvt_c32 = codecvt<char32_t, char, mbstate_t>;
> auto loc_c = locale::classic ();
> VERIFY (has_facet<codecvt_c32> (loc_c));
> +
> auto &cvt = use_facet<codecvt_c32> (loc_c);
> test_utf8_utf32_codecvts (cvt);
>
> - auto cvt_ptr = to_unique_ptr (new codecvt_utf8<char32_t> ());
> - test_utf8_utf32_codecvts (*cvt_ptr);
> + auto cvt2 = codecvt_utf8<char32_t> ();
> + test_utf8_utf32_codecvts (cvt2);
> }
>
> void
> @@ -42,21 +43,22 @@ test_utf8_utf16_codecvts ()
> using codecvt_c16 = codecvt<char16_t, char, mbstate_t>;
> auto loc_c = locale::classic ();
> VERIFY (has_facet<codecvt_c16> (loc_c));
> +
> auto &cvt = use_facet<codecvt_c16> (loc_c);
> test_utf8_utf16_cvts (cvt);
>
> - auto cvt_ptr = to_unique_ptr (new codecvt_utf8_utf16<char16_t> ());
> - test_utf8_utf16_cvts (*cvt_ptr);
> + auto cvt2 = codecvt_utf8_utf16<char16_t> ();
> + test_utf8_utf16_cvts (cvt2);
>
> - auto cvt_ptr2 = to_unique_ptr (new codecvt_utf8_utf16<char32_t> ());
> - test_utf8_utf16_cvts (*cvt_ptr2);
> + auto cvt3 = codecvt_utf8_utf16<char32_t> ();
> + test_utf8_utf16_cvts (cvt3);
> }
>
> void
> test_utf8_ucs2_codecvts ()
> {
> - auto cvt_ptr = to_unique_ptr (new codecvt_utf8<char16_t> ());
> - test_utf8_ucs2_cvts (*cvt_ptr);
> + auto cvt = codecvt_utf8<char16_t> ();
> + test_utf8_ucs2_cvts (cvt);
> }
>
> int
> diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h
> b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h
> index 99d1a4684..fbdc7a35b 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.h
> @@ -15,18 +15,11 @@
> // with this library; see the file COPYING3. If not see
> // <http://www.gnu.org/licenses/>.
>
> +#include <algorithm>
> #include <locale>
> #include <string>
> -#include <memory>
> #include <testsuite_hooks.h>
>
> -template <typename T>
> -std::unique_ptr<T>
> -to_unique_ptr (T *ptr)
> -{
> - return std::unique_ptr<T> (ptr);
> -}
> -
> struct test_offsets_ok
> {
> size_t in_size, out_size;
> diff --git
> a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc
> b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc
> index 169504939..f7a0a4fd8 100644
> --- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc
> +++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc
> @@ -27,8 +27,8 @@ void
> test_utf8_utf32_codecvts ()
> {
> #if __SIZEOF_WCHAR_T__ == 4
> - auto cvt_ptr = to_unique_ptr (new codecvt_utf8<wchar_t> ());
> - test_utf8_utf32_codecvts (*cvt_ptr);
> + auto cvt = codecvt_utf8<wchar_t> ();
> + test_utf8_utf32_codecvts (cvt);
> #endif
> }
>
> @@ -36,8 +36,8 @@ void
> test_utf8_utf16_codecvts ()
> {
> #if __SIZEOF_WCHAR_T__ >= 2
> - auto cvt_ptr = to_unique_ptr (new codecvt_utf8_utf16<wchar_t> ());
> - test_utf8_utf16_cvts (*cvt_ptr);
> + auto cvt = codecvt_utf8_utf16<wchar_t> ();
> + test_utf8_utf16_cvts (cvt);
> #endif
> }
>
> @@ -45,8 +45,8 @@ void
> test_utf8_ucs2_codecvts ()
> {
> #if __SIZEOF_WCHAR_T__ == 2
> - auto cvt_ptr = to_unique_ptr (new codecvt_utf8<wchar_t> ());
> - test_utf8_ucs2_cvts (*cvt_ptr);
> + auto cvt = codecvt_utf8<wchar_t> ();
> + test_utf8_ucs2_cvts (cvt);
> #endif
> }
>
> --
> 2.34.1
>
>
>
On 17/01/23 22:12 +0100, Dimitrij Mijoski wrote:
>Stop using unique_ptr, create some objects directly.
>
>libstdc++-v3/ChangeLog:
>
> * testsuite/22_locale/codecvt/codecvt_unicode.cc: Simplify.
> * testsuite/22_locale/codecvt/codecvt_unicode.h: Simplify.
> * testsuite/22_locale/codecvt/codecvt_unicode_wchar_t.cc: Simplify.
>---
> .../22_locale/codecvt/codecvt_unicode.cc | 18 ++++++++++--------
> .../22_locale/codecvt/codecvt_unicode.h | 9 +--------
> .../codecvt/codecvt_unicode_wchar_t.cc | 12 ++++++------
> 3 files changed, 17 insertions(+), 22 deletions(-)
>
>diff --git a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.cc b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.cc
>index ae4b6c896..3d7393e4a 100644
>--- a/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.cc
>+++ b/libstdc++-v3/testsuite/22_locale/codecvt/codecvt_unicode.cc
>@@ -29,11 +29,12 @@ test_utf8_utf32_codecvts ()
> using codecvt_c32 = codecvt<char32_t, char, mbstate_t>;
> auto loc_c = locale::classic ();
> VERIFY (has_facet<codecvt_c32> (loc_c));
>+
> auto &cvt = use_facet<codecvt_c32> (loc_c);
> test_utf8_utf32_codecvts (cvt);
>
>- auto cvt_ptr = to_unique_ptr (new codecvt_utf8<char32_t> ());
>- test_utf8_utf32_codecvts (*cvt_ptr);
>+ auto cvt2 = codecvt_utf8<char32_t> ();
This doesn't compile in C++11 or C++14, because there's no guaranteed
elision.
I've pushed the attached change instead. Thanks for the patch.
On Wed, 2023-01-18 at 18:53 +0000, Jonathan Wakely wrote:
> This doesn't compile in C++11 or C++14, because there's no guaranteed
> elision.
I see. I just looked up in the docs and found that I need to put
--target_board=unix/-std=c++11 inside RUNTESTFLAGS to test in C++11
mode.
On Wed, 18 Jan 2023 at 19:52, Dimitrij Mijoski wrote:
>
> On Wed, 2023-01-18 at 18:53 +0000, Jonathan Wakely wrote:
> > This doesn't compile in C++11 or C++14, because there's no guaranteed
> > elision.
>
> I see. I just looked up in the docs and found that I need to put
> --target_board=unix/-std=c++11 inside RUNTESTFLAGS to test in C++11
> mode.
That's right. I have multiple options used by default, via ~/.dejagnurc
$ cat ~/.dejagnurc
# Need to test if $tool exists prior to the r11-551 change.
if { [info exists tool] && "$tool" == "libstdc++" } {
global tool_timeout
set tool_timeout 50
puts "dejagnu - timeout default set to ${tool_timeout}s"
set target_list {
"unix{,-D_GLIBCXX_USE_CXX11_ABI=0,-std=gnu++2b,-std=gnu++11}" }
}
This makes the testsuite take four times as long, but increases
coverage and finds issues like this one. As long as somebody runs the
extended list of options now and then, we don't need them to all be
run for everybody.
@@ -29,11 +29,12 @@ test_utf8_utf32_codecvts ()
using codecvt_c32 = codecvt<char32_t, char, mbstate_t>;
auto loc_c = locale::classic ();
VERIFY (has_facet<codecvt_c32> (loc_c));
+
auto &cvt = use_facet<codecvt_c32> (loc_c);
test_utf8_utf32_codecvts (cvt);
- auto cvt_ptr = to_unique_ptr (new codecvt_utf8<char32_t> ());
- test_utf8_utf32_codecvts (*cvt_ptr);
+ auto cvt2 = codecvt_utf8<char32_t> ();
+ test_utf8_utf32_codecvts (cvt2);
}
void
@@ -42,21 +43,22 @@ test_utf8_utf16_codecvts ()
using codecvt_c16 = codecvt<char16_t, char, mbstate_t>;
auto loc_c = locale::classic ();
VERIFY (has_facet<codecvt_c16> (loc_c));
+
auto &cvt = use_facet<codecvt_c16> (loc_c);
test_utf8_utf16_cvts (cvt);
- auto cvt_ptr = to_unique_ptr (new codecvt_utf8_utf16<char16_t> ());
- test_utf8_utf16_cvts (*cvt_ptr);
+ auto cvt2 = codecvt_utf8_utf16<char16_t> ();
+ test_utf8_utf16_cvts (cvt2);
- auto cvt_ptr2 = to_unique_ptr (new codecvt_utf8_utf16<char32_t> ());
- test_utf8_utf16_cvts (*cvt_ptr2);
+ auto cvt3 = codecvt_utf8_utf16<char32_t> ();
+ test_utf8_utf16_cvts (cvt3);
}
void
test_utf8_ucs2_codecvts ()
{
- auto cvt_ptr = to_unique_ptr (new codecvt_utf8<char16_t> ());
- test_utf8_ucs2_cvts (*cvt_ptr);
+ auto cvt = codecvt_utf8<char16_t> ();
+ test_utf8_ucs2_cvts (cvt);
}
int
@@ -15,18 +15,11 @@
// with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
+#include <algorithm>
#include <locale>
#include <string>
-#include <memory>
#include <testsuite_hooks.h>
-template <typename T>
-std::unique_ptr<T>
-to_unique_ptr (T *ptr)
-{
- return std::unique_ptr<T> (ptr);
-}
-
struct test_offsets_ok
{
size_t in_size, out_size;
@@ -27,8 +27,8 @@ void
test_utf8_utf32_codecvts ()
{
#if __SIZEOF_WCHAR_T__ == 4
- auto cvt_ptr = to_unique_ptr (new codecvt_utf8<wchar_t> ());
- test_utf8_utf32_codecvts (*cvt_ptr);
+ auto cvt = codecvt_utf8<wchar_t> ();
+ test_utf8_utf32_codecvts (cvt);
#endif
}
@@ -36,8 +36,8 @@ void
test_utf8_utf16_codecvts ()
{
#if __SIZEOF_WCHAR_T__ >= 2
- auto cvt_ptr = to_unique_ptr (new codecvt_utf8_utf16<wchar_t> ());
- test_utf8_utf16_cvts (*cvt_ptr);
+ auto cvt = codecvt_utf8_utf16<wchar_t> ();
+ test_utf8_utf16_cvts (cvt);
#endif
}
@@ -45,8 +45,8 @@ void
test_utf8_ucs2_codecvts ()
{
#if __SIZEOF_WCHAR_T__ == 2
- auto cvt_ptr = to_unique_ptr (new codecvt_utf8<wchar_t> ());
- test_utf8_ucs2_cvts (*cvt_ptr);
+ auto cvt = codecvt_utf8<wchar_t> ();
+ test_utf8_ucs2_cvts (cvt);
#endif
}