tst_containerapisymmetry: remove the extra push_back
... and make sure it cannot happen again by using Extract Method to let the compiler do the counting between the resize and the sequence-of-push_back alternatives, because this author clearly can't. Amends 3c0fdd7341ed4bff9b5f041e9f4646265d142303. Pick-to: 6.6 6.5 Change-Id: If18f30d60f556e5e668876a38423f3e519fb79b0 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
9dd1953218
commit
0a86a77e5f
@ -781,10 +781,25 @@ void tst_ContainerApiSymmetry::resize_impl() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
[[maybe_unused]]
|
||||||
constexpr bool is_vector_v = false;
|
constexpr bool is_vector_v = false;
|
||||||
template <typename...Args>
|
template <typename...Args>
|
||||||
constexpr bool is_vector_v<std::vector<Args...>> = true;
|
constexpr bool is_vector_v<std::vector<Args...>> = true;
|
||||||
|
|
||||||
|
template <typename Container, typename Value>
|
||||||
|
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<Container>) {
|
||||||
|
while (c.size() < n)
|
||||||
|
c.push_back(v);
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
c.resize(n, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Container>
|
template <typename Container>
|
||||||
void tst_ContainerApiSymmetry::copesWithValueTypesWithConstMembers_impl()
|
void tst_ContainerApiSymmetry::copesWithValueTypesWithConstMembers_impl()
|
||||||
{
|
{
|
||||||
@ -815,24 +830,9 @@ void tst_ContainerApiSymmetry::copesWithValueTypesWithConstMembers_impl()
|
|||||||
// make sure they work
|
// make sure they work
|
||||||
c.reserve(S(5));
|
c.reserve(S(5));
|
||||||
c.shrink_to_fit();
|
c.shrink_to_fit();
|
||||||
#ifdef __GLIBCXX__ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83981
|
wrap_resize(c, 1, V(42));
|
||||||
if constexpr (is_vector_v<Container>) {
|
|
||||||
c.push_back(V(42));
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
c.resize(1, V(42));
|
|
||||||
}
|
|
||||||
QCOMPARE(c[0], V(42));
|
QCOMPARE(c[0], V(42));
|
||||||
#ifdef __GLIBCXX__ // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83981
|
wrap_resize(c, 2, V(48));
|
||||||
if constexpr (is_vector_v<Container>) {
|
|
||||||
c.push_back(V(48));
|
|
||||||
c.push_back(V(48));
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
c.resize(2, V(48));
|
|
||||||
}
|
|
||||||
QCOMPARE(c[0], V(42));
|
QCOMPARE(c[0], V(42));
|
||||||
QCOMPARE(c[1], V(48));
|
QCOMPARE(c[1], V(48));
|
||||||
c.clear();
|
c.clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user