diff --git a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp index 05d8dac126a..b069dd4618c 100644 --- a/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp +++ b/tests/auto/corelib/tools/containerapisymmetry/tst_containerapisymmetry.cpp @@ -781,10 +781,25 @@ void tst_ContainerApiSymmetry::resize_impl() const } template +[[maybe_unused]] constexpr bool is_vector_v = false; template constexpr bool is_vector_v> = true; +template +void wrap_resize(Container &c, typename Container::size_type n, const Value &v) +{ +#ifdef __GLIBCXX__ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83981 + if constexpr (is_vector_v) { + while (c.size() < n) + c.push_back(v); + } else +#endif + { + c.resize(n, v); + } +} + template void tst_ContainerApiSymmetry::copesWithValueTypesWithConstMembers_impl() { @@ -815,24 +830,9 @@ void tst_ContainerApiSymmetry::copesWithValueTypesWithConstMembers_impl() // make sure they work c.reserve(S(5)); c.shrink_to_fit(); -#ifdef __GLIBCXX__ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83981 - if constexpr (is_vector_v) { - c.push_back(V(42)); - } else -#endif - { - c.resize(1, V(42)); - } + wrap_resize(c, 1, V(42)); QCOMPARE(c[0], V(42)); -#ifdef __GLIBCXX__ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83981 - if constexpr (is_vector_v) { - c.push_back(V(48)); - c.push_back(V(48)); - } else -#endif - { - c.resize(2, V(48)); - } + wrap_resize(c, 2, V(48)); QCOMPARE(c[0], V(42)); QCOMPARE(c[1], V(48)); c.clear();