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
Next Next commit
Tweak so that no configuration change is needed
... for existing integrations (like FB's buck integration) to keep compiling
  • Loading branch information
pdillinger committed Apr 14, 2020
commit 3de7ca9202e731928c571e3e5959bdb60212da1f
18 changes: 4 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,18 +512,11 @@ include(CxxFlags)
get_cxx_std_flags(CMAKE_REQUIRED_FLAGS)

CHECK_CXX_SOURCE_COMPILES("
template< typename F >
int apply(F f) {
return f();
}

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

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

int value_;
Expand All @@ -533,17 +526,14 @@ int main() {
test t;
return t.lambda();
}
" HAVE_IMPLICIT_THIS_LAMBDA_CAPTURE
" USE_EXPLICIT_CAPTURE_THIS
)

unset(CMAKE_REQUIRED_FLAGS)

if(HAVE_IMPLICIT_THIS_LAMBDA_CAPTURE)
set(ROCKSDB_THIS_LAMBDA_CAPTURE "=")
else()
set(ROCKSDB_THIS_LAMBDA_CAPTURE "=, this")
if(USE_EXPLICIT_CAPTURE_THIS)
add_definitions(-DROCKSDB_EXPLICIT_CAPTURE_THIS)
endif()
add_definitions(-DROCKSDB_THIS_LAMBDA_CAPTURE=${ROCKSDB_THIS_LAMBDA_CAPTURE})


include_directories(${PROJECT_SOURCE_DIR})
Expand Down
10 changes: 4 additions & 6 deletions build_tools/build_detect_platform
Original file line number Diff line number Diff line change
Expand Up @@ -702,12 +702,12 @@ EOF
fi


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

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

int value_;
Expand All @@ -719,9 +719,7 @@ int main() {
}
EOF
if [ "$?" = 0 ]; then
COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_THIS_LAMBDA_CAPTURE=\"=\""
else
COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_THIS_LAMBDA_CAPTURE=\"=, this\""
COMMON_FLAGS="$COMMON_FLAGS -DROCKSDB_EXPLICIT_CAPTURE_THIS"
fi

if [ "$FBCODE_BUILD" != "true" -a "$PLATFORM" = OS_LINUX ]; then
Expand Down
14 changes: 7 additions & 7 deletions cmake/modules/CxxFlags.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
macro(get_cxx_std_flags FLAGS_VARIABLE)
if( CMAKE_CXX_STANDARD_REQUIRED )
set(${FLAGS_VARIABLE} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION})
else()
set(${FLAGS_VARIABLE} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_EXTENSION_COMPILE_OPTION})
endif()
endmacro()
macro(get_cxx_std_flags FLAGS_VARIABLE)
if( CMAKE_CXX_STANDARD_REQUIRED )
set(${FLAGS_VARIABLE} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION})
else()
set(${FLAGS_VARIABLE} ${CMAKE_CXX${CMAKE_CXX_STANDARD}_EXTENSION_COMPILE_OPTION})
endif()
endmacro()
2 changes: 1 addition & 1 deletion db/log_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "test_util/sync_point.h"
#include "util/coding.h"
#include "util/crc32c.h"
#include "util/util.h"
#include "port/lang.h"

namespace ROCKSDB_NAMESPACE {
namespace log {
Expand Down
2 changes: 1 addition & 1 deletion db/memtable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "util/autovector.h"
#include "util/coding.h"
#include "util/mutexlock.h"
#include "util/util.h"
#include "port/lang.h"

namespace ROCKSDB_NAMESPACE {

Expand Down
2 changes: 1 addition & 1 deletion db/write_batch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include "util/coding.h"
#include "util/duplicate_detector.h"
#include "util/string_util.h"
#include "util/util.h"
#include "port/lang.h"

namespace ROCKSDB_NAMESPACE {

Expand Down
2 changes: 1 addition & 1 deletion include/rocksdb/file_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct FileOptions : EnvOptions {

FileOptions(const FileOptions& opts)
: EnvOptions(opts), io_options(opts.io_options) {}

FileOptions& operator=(const FileOptions& opts) = default;
};

Expand Down
1 change: 1 addition & 0 deletions memory/concurrent_arena.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <utility>
#include "memory/allocator.h"
#include "memory/arena.h"
#include "port/lang.h"
#include "port/likely.h"
#include "util/core_local.h"
#include "util/mutexlock.h"
Expand Down
7 changes: 7 additions & 0 deletions util/util.h → port/lang.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@
#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
1 change: 1 addition & 0 deletions table/block_based/block_based_table_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "db/dbformat.h"
#include "index_builder.h"
#include "port/lang.h"

#include "rocksdb/cache.h"
#include "rocksdb/comparator.h"
Expand Down
2 changes: 1 addition & 1 deletion table/block_based/block_based_table_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#include "util/crc32c.h"
#include "util/stop_watch.h"
#include "util/string_util.h"
#include "util/util.h"
#include "port/lang.h"
#include "util/xxhash.h"

namespace ROCKSDB_NAMESPACE {
Expand Down
6 changes: 6 additions & 0 deletions third-party/folly/folly/synchronization/Baton.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
#include <folly/synchronization/WaitOptions.h>
#include <folly/synchronization/detail/Spin.h>

#ifdef ROCKSDB_EXPLICIT_CAPTURE_THIS
#define ROCKSDB_THIS_LAMBDA_CAPTURE =,this
#else
#define ROCKSDB_THIS_LAMBDA_CAPTURE =
#endif

namespace folly {

/// A Baton allows a thread to block once and be awoken. Captures a
Expand Down
2 changes: 1 addition & 1 deletion util/crc32c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <wmmintrin.h>
#endif
#include "util/coding.h"
#include "util/util.h"
#include "port/lang.h"

#include "util/crc32c_arm64.h"

Expand Down
2 changes: 1 addition & 1 deletion util/hash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <string.h>
#include "util/coding.h"
#include "util/hash.h"
#include "util/util.h"
#include "port/lang.h"
#include "util/xxhash.h"

namespace ROCKSDB_NAMESPACE {
Expand Down
2 changes: 1 addition & 1 deletion util/murmurhash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
is under the MIT license.
*/
#include "murmurhash.h"
#include "util/util.h"
#include "port/lang.h"

#if defined(__x86_64__)

Expand Down
2 changes: 1 addition & 1 deletion util/xxhash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static void* XXH_memcpy(void* dest, const void* src, size_t size) { return memcp
#include "xxhash.h"

/* BEGIN RocksDB customizations */
#include "util/util.h" /* for FALLTHROUGH_INTENDED, inserted as appropriate */
#include "port/lang.h" /* for FALLTHROUGH_INTENDED, inserted as appropriate */
/* END RocksDB customizations */

/* *************************************
Expand Down