Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 compatibility #6697

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
af91b57
Fix implicit capture of ‘this’ via ‘[=]’ is deprecated in C++20
syoliver-se Mar 22, 2020
880549c
Allow to choose C++ version in cmake command line
syoliver-se Mar 22, 2020
4a1df6e
Fix deprecated copy warning in gcc 9
syoliver-se Apr 5, 2020
2756589
Minimal Rebuild is deprecated in visual studio since 2015 and is forb…
syoliver-se Apr 5, 2020
cea96d0
random_shuffle is deprecated in C++14 and removed in C++17
syoliver-se Apr 5, 2020
4e46260
Fix implicit this lambda capture deprecation
syoliver-se Apr 5, 2020
96f7359
Add implicit lambda capture in raw makefile
syoliver-se Apr 6, 2020
5962870
Add MSVC2019 to AppVeyor
syoliver-se Apr 6, 2020
d31e395
Add gcc-9 with c++11 and c++20 to travis
syoliver-se Apr 6, 2020
43eee91
Merge remote-tracking branch 'origin/master' into pr/6648
pdillinger Apr 10, 2020
87f3151
Reduce cmake variants built on each PR
pdillinger Apr 10, 2020
831fb29
Fix whitespace / noeol in CMakeLists.txt
pdillinger Apr 10, 2020
3de7ca9
Tweak so that no configuration change is needed
pdillinger Apr 10, 2020
c9e951e
Unified RandomShuffle
pdillinger Apr 13, 2020
756ea7f
Remove 'this' capture from folly import
pdillinger Apr 14, 2020
1b7b028
Remove an unnecessary capture spec
pdillinger Apr 14, 2020
dda5107
make format
pdillinger Apr 14, 2020
427a33d
Merge remote-tracking branch 'origin/master' into cxx20
pdillinger Apr 14, 2020
882a9d5
Fixup after merge
pdillinger Apr 14, 2020
c19c8ac
Better capture solution for Baton.h
pdillinger Apr 14, 2020
da5b61e
Actually, just use explicit capture
pdillinger Apr 14, 2020
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
Prev Previous commit
Actually, just use explicit capture
... and get rid of the macro mess for [=,this]
  • Loading branch information
pdillinger committed Apr 14, 2020
commit da5b61e0ce6004b81bfc0c0a63e2888f9792bcc8
29 changes: 0 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -507,35 +507,6 @@ if(HAVE_AUXV_GETAUXVAL)
add_definitions(-DROCKSDB_AUXV_GETAUXVAL_PRESENT)
endif()

# Workaround to get c++ std version option coming from CMAKE_CXX_STANDARD for try_compile
include(CxxFlags)
get_cxx_std_flags(CMAKE_REQUIRED_FLAGS)

CHECK_CXX_SOURCE_COMPILES("
struct test {
test() : value_(0) {}

int lambda() {
return [=,this]() { return value_; }();
}

int value_;
};

int main() {
test t;
return t.lambda();
}
" USE_EXPLICIT_CAPTURE_THIS
)

unset(CMAKE_REQUIRED_FLAGS)

if(USE_EXPLICIT_CAPTURE_THIS)
add_definitions(-DROCKSDB_EXPLICIT_CAPTURE_THIS)
endif()


include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/gtest-1.8.1/fused-src)
Expand Down
20 changes: 0 additions & 20 deletions build_tools/build_detect_platform
Original file line number Diff line number Diff line change
Expand Up @@ -706,26 +706,6 @@ EOF
fi


$CXX $PLATFORM_CXXFLAGS $COMMON_FLAGS -Werror -x c++ - -o /dev/null 2>/dev/null <<EOF
struct test {
test() : value_(0) {}

int lambda() {
return [=,this]() { return value_; }();
}

int value_;
};

int main() {
test t;
return t.lambda();
}
EOF
if [ "$?" = 0 ]; then
COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_EXPLICIT_CAPTURE_THIS"
fi

if [ "$FBCODE_BUILD" != "true" -a "$PLATFORM" = OS_LINUX ]; then
$CXX $COMMON_FLAGS $PLATFORM_SHARED_CFLAGS -x c++ -c - -o test_dl.o 2>/dev/null <<EOF
void dummy_func() {}
Expand Down
7 changes: 3 additions & 4 deletions memory/concurrent_arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ class ConcurrentArena : public Allocator {
size_t huge_page_size = 0);

char* Allocate(size_t bytes) override {
return AllocateImpl(
bytes, false /*force_arena*/,
[ROCKSDB_THIS_LAMBDA_CAPTURE]() { return arena_.Allocate(bytes); });
return AllocateImpl(bytes, false /*force_arena*/,
[this, bytes]() { return arena_.Allocate(bytes); });
}

char* AllocateAligned(size_t bytes, size_t huge_page_size = 0,
Expand All @@ -61,7 +60,7 @@ class ConcurrentArena : public Allocator {
(rounded_up % sizeof(void*)) == 0);

return AllocateImpl(rounded_up, huge_page_size != 0 /*force_arena*/,
[ROCKSDB_THIS_LAMBDA_CAPTURE]() {
[this, rounded_up, huge_page_size, logger]() {
return arena_.AllocateAligned(rounded_up,
huge_page_size, logger);
});
Expand Down
7 changes: 0 additions & 7 deletions port/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,3 @@
#define FALLTHROUGH_INTENDED do {} while (0)
#endif
#endif

#if defined(ROCKSDB_EXPLICIT_CAPTURE_THIS) || __cplusplus >= 202002L
// C++20 deprecates implicit capture of 'this' in [=]
#define ROCKSDB_THIS_LAMBDA_CAPTURE =, this
#else
#define ROCKSDB_THIS_LAMBDA_CAPTURE =
#endif
15 changes: 7 additions & 8 deletions table/block_based/block_based_table_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,14 +662,13 @@ BlockBasedTableBuilder::BlockBasedTableBuilder(
rep_->pc_rep->compress_thread_pool.reserve(
rep_->compression_opts.parallel_threads);
for (uint32_t i = 0; i < rep_->compression_opts.parallel_threads; i++) {
rep_->pc_rep->compress_thread_pool.emplace_back(
[ROCKSDB_THIS_LAMBDA_CAPTURE] {
BGWorkCompression(*(rep_->compression_ctxs[i]),
rep_->verify_ctxs[i].get());
});
rep_->pc_rep->compress_thread_pool.emplace_back([this, i] {
BGWorkCompression(*(rep_->compression_ctxs[i]),
rep_->verify_ctxs[i].get());
});
}
rep_->pc_rep->write_thread.reset(new port::Thread(
[ROCKSDB_THIS_LAMBDA_CAPTURE] { BGWorkWriteRawBlock(); }));
rep_->pc_rep->write_thread.reset(
new port::Thread([this] { BGWorkWriteRawBlock(); }));
}
}

Expand Down Expand Up @@ -834,7 +833,7 @@ void BlockBasedTableBuilder::Flush() {
if (first_block) {
std::unique_lock<std::mutex> lock(r->pc_rep->first_block_mutex);
r->pc_rep->first_block_cond.wait(lock,
[=] { return !r->pc_rep->first_block; });
[r] { return !r->pc_rep->first_block; });
}
} else {
WriteBlock(&r->data_block, &r->pending_handle, true /* is_data_block */);
Expand Down
6 changes: 2 additions & 4 deletions utilities/blob_db/blob_db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -622,17 +622,15 @@ void BlobDBImpl::MarkUnreferencedBlobFilesObsolete() {
const SequenceNumber obsolete_seq = GetLatestSequenceNumber();

MarkUnreferencedBlobFilesObsoleteImpl(
[ROCKSDB_THIS_LAMBDA_CAPTURE](
const std::shared_ptr<BlobFile>& blob_file) {
[this, obsolete_seq](const std::shared_ptr<BlobFile>& blob_file) {
WriteLock file_lock(&blob_file->mutex_);
return MarkBlobFileObsoleteIfNeeded(blob_file, obsolete_seq);
});
}

void BlobDBImpl::MarkUnreferencedBlobFilesObsoleteDuringOpen() {
MarkUnreferencedBlobFilesObsoleteImpl(
[ROCKSDB_THIS_LAMBDA_CAPTURE](
const std::shared_ptr<BlobFile>& blob_file) {
[this](const std::shared_ptr<BlobFile>& blob_file) {
return MarkBlobFileObsoleteIfNeeded(blob_file, /* obsolete_seq */ 0);
});
}
Expand Down