File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -156,7 +156,6 @@ template <typename T, uint32_t N>
156156class TfSmallVector : public TfSmallVectorBase
157157{
158158public:
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 }
Original file line number Diff line number Diff 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+
322343static void
323344testGrowth ()
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;
You can’t perform that action at this time.
0 commit comments