qqiangwu / cppsafe

Cpp lifetime safety profile static analyzer
MIT License
48 stars 1 forks source link

rocksdb: move and reset sub-objects #33

Open qqiangwu opened 7 months ago

qqiangwu commented 7 months ago
SmallestKeyHeap create_level_heap(Compaction* c, const Comparator* ucmp) {
  SmallestKeyHeap smallest_key_priority_q =
      SmallestKeyHeap(SmallestKeyHeapComparator(ucmp));

  InputFileInfo input_file;

  for (size_t l = 0; l < c->num_input_levels(); l++) {
    if (c->num_input_files(l) != 0) {
      if (l == 0 && c->start_level() == 0) {
        for (size_t i = 0; i < c->num_input_files(0); i++) {
          input_file.f = c->input(0, i);
          input_file.level = 0;
          input_file.index = i;
          smallest_key_priority_q.push(std::move(input_file));
        }
      } else {
        input_file.f = c->input(l, 0);
        input_file.level = l;
        input_file.index = 0;
        smallest_key_priority_q.push(std::move(input_file));
      }
    }
  }
  return smallest_key_priority_q;
}

yields

/Users/wuqq/dev/rocksdb-main/db/compaction/compaction_picker_universal.cc:301:48: warning: use a moved-from object
  301 |         smallest_key_priority_q.push(std::move(input_file));
      |                                                ^~~~~~~~~~
/Users/wuqq/dev/rocksdb-main/db/compaction/compaction_picker_universal.cc:301:38: note: moved here
  301 |         smallest_key_priority_q.push(std::move(input_file));
      |                                      ^~~~~~~~~~~~~~~~~~~~~
/Users/wuqq/dev/rocksdb-main/db/compaction/compaction_picker_universal.cc:295:50: warning: use a moved-from object
  295 |           smallest_key_priority_q.push(std::move(input_file));
      |                                                  ^~~~~~~~~~
/Users/wuqq/dev/rocksdb-main/db/compaction/compaction_picker_universal.cc:301:38: note: moved here
  301 |         smallest_key_priority_q.push(std::move(input_file));
      |                                      ^~~~~~~~~~~~~~~~~~~~~
/Users/wuqq/dev/rocksdb-main/db/compaction/compaction_picker_universal.cc:372:46: warning: use a moved-from object
  372 |       smallest_key_priority_q.push(std::move(next));
      |                                              ^~~~
/Users/wuqq/dev/rocksdb-main/db/compaction/compaction_picker_universal.cc:372:36: note: moved here
  372 |       smallest_key_priority_q.push(std::move(next));
      |                                    ^~~~~~~~~~~~~~~
3 warnings generated.
qqiangwu commented 6 months ago
Aggr a;

eat(std::move(a.o));

// a should not be used anymore

a.o = {}
// a is okay to use