Skip to content

Commit 2abb85b

Browse files
committed
Avoid warning with rvalue construction without local storage
1 parent 15a2bff commit 2abb85b

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

pxr/base/tf/smallVector.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ template <typename T, uint32_t N>
156156
class TfSmallVector : public TfSmallVectorBase
157157
{
158158
public:
159-
160159
/// XXX: Functionality currently missing, and which we would like to add as
161160
/// needed:
162161
/// - emplace
@@ -240,8 +239,12 @@ class TfSmallVector : public TfSmallVectorBase
240239
// sizes. Note that capacities will be the same in this case, so no
241240
// need to swap those.
242241
else {
243-
_UninitializedMove(rhs.begin(), rhs.end(), begin());
244-
rhs._Destruct();
242+
// If N is 0, this means that rhs is empty and there are no elements that need moving or destroying
243+
// This avoids warnings in GCC.
244+
if constexpr (N > 0) {
245+
_UninitializedMove(rhs.begin(), rhs.end(), begin());
246+
rhs._Destruct();
247+
}
245248
}
246249
std::swap(_size, rhs._size);
247250
}

pxr/base/tf/testenv/smallVector.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,27 @@ testNoLocalStorage()
319319
TF_AXIOM(v.capacity() == 4);
320320
}
321321

322+
static void
323+
testEmptyMoveNoLocalStorage()
324+
{
325+
// Empty move construction
326+
TfSmallVector<int, 0> v{TfSmallVector<int, 0>{}};
327+
TF_AXIOM(v.size() == 0);
328+
TF_AXIOM(v.capacity() == 0);
329+
330+
v.push_back(1414);
331+
TF_AXIOM(v.size() == 1);
332+
TF_AXIOM(v.capacity() == 1);
333+
TF_AXIOM(v.front() == 1414);
334+
TF_AXIOM(v.back() == 1414);
335+
336+
v.push_back(1515);
337+
TF_AXIOM(v.size() == 2);
338+
TF_AXIOM(v.capacity() == 2);
339+
TF_AXIOM(v.front() == 1414);
340+
TF_AXIOM(v.back() == 1515);
341+
}
342+
322343
static void
323344
testGrowth()
324345
{
@@ -1588,6 +1609,8 @@ Test_TfSmallVector()
15881609
testConstructors();
15891610
std::cout << "testNoLocalStorage" << std::endl;
15901611
testNoLocalStorage();
1612+
std::cout << "testEmptyMoveNoLocalStorage" << std::endl;
1613+
testEmptyMoveNoLocalStorage();
15911614
std::cout << "testGrowth" << std::endl;
15921615
testGrowth();
15931616
std::cout << "testIteration" << std::endl;

0 commit comments

Comments
 (0)