Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pxr/base/tf/smallVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ template <typename T, uint32_t N>
class TfSmallVector : public TfSmallVectorBase
{
public:

/// XXX: Functionality currently missing, and which we would like to add as
/// needed:
/// - emplace
Expand Down Expand Up @@ -240,8 +239,12 @@ class TfSmallVector : public TfSmallVectorBase
// sizes. Note that capacities will be the same in this case, so no
// need to swap those.
else {
_UninitializedMove(rhs.begin(), rhs.end(), begin());
rhs._Destruct();
// If N is 0, this means that rhs is empty and there are no elements that need moving or destroying
// This avoids warnings in GCC.
if constexpr (N > 0) {
_UninitializedMove(rhs.begin(), rhs.end(), begin());
rhs._Destruct();
}
}
std::swap(_size, rhs._size);
}
Expand Down
29 changes: 29 additions & 0 deletions pxr/base/tf/testenv/smallVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,33 @@ testNoLocalStorage()
TF_AXIOM(v.capacity() == 4);
}

static void
testEmptyMoveNoLocalStorage()
{
TfSmallVector<int, 0> empty{};
{
// Empty move construction
TfSmallVector<int, 0> v{std::move(empty)};
TF_AXIOM(v.size() == 0);
TF_AXIOM(v.capacity() == 0);

v.push_back(1414);
TF_AXIOM(v.size() == 1);
TF_AXIOM(v.capacity() == 1);
TF_AXIOM(v.front() == 1414);
TF_AXIOM(v.back() == 1414);

v.push_back(1515);
TF_AXIOM(v.size() == 2);
TF_AXIOM(v.capacity() == 2);
TF_AXIOM(v.front() == 1414);
TF_AXIOM(v.back() == 1515);
}

TF_AXIOM(empty.size() == 0);
TF_AXIOM(empty.capacity() == 0);
}

static void
testGrowth()
{
Expand Down Expand Up @@ -1588,6 +1615,8 @@ Test_TfSmallVector()
testConstructors();
std::cout << "testNoLocalStorage" << std::endl;
testNoLocalStorage();
std::cout << "testEmptyMoveNoLocalStorage" << std::endl;
testEmptyMoveNoLocalStorage();
std::cout << "testGrowth" << std::endl;
testGrowth();
std::cout << "testIteration" << std::endl;
Expand Down
Loading