-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Fix compilation with GCC9 and MSVC 2019 with CMAKE_CXX_STANDARD=20 #6648
Conversation
…biden with /std:c++latest
@syoliver Are these changes still compatible with VS 2015? |
According to appveyor it should be compatible, but I admit I didn't test myself with VS 2015. I should try the /Gm with 2015 before publishing the PR, but according to the documentation it should have been deprecated long time ago. The default is always -std=c++11, I just added a way to compile with C++20 in the cmake. The implicit capture of this is tested in the makefile/cmakelists because depending on the compiler, [=] and [=, this] can compile or not. The only issue I have is with clang XCode makefile build, I don't find why it fails :-( |
@syoliver As long as AppVeyor for VS2015 passes then I am a happy person :-) |
(Add logs...)
Timeout reached in travis, but it seems to work. @adamretter : Visual Studio 2015 doesn't have warning on /Gm, then I leaved this option for 2015. 2017 and 2019 have warning, 2019 with /std:c++latest has error, then I removed this option for 2017 and more. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cheng-Chang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@syoliver has updated the pull request. Re-import the pull request |
@syoliver has updated the pull request. Re-import the pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM
@@ -1343,8 +1344,9 @@ TEST_F(DBBloomFilterTest, OptimizeFiltersForHits) { | |||
for (int i = 0; i < numkeys; i += 2) { | |||
keys.push_back(i); | |||
} | |||
std::random_shuffle(std::begin(keys), std::end(keys)); | |||
|
|||
std::random_device rng; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should unify all of these, including
test_util/transaction_test_util.cc: std::shuffle(set_vec.begin(), set_vec.end(), std::random_device{});
with a single implementation in util/random.h,cc
Though we can do this after merging this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdillinger Yes you are right, I would be happy to propose something after this PR if it's good for you. Else I can try here, but I would prefer making it in another step.
@@ -49,7 +49,9 @@ class ConcurrentArena : public Allocator { | |||
|
|||
char* Allocate(size_t bytes) override { | |||
return AllocateImpl(bytes, false /*force_arena*/, | |||
[=]() { return arena_.Allocate(bytes); }); | |||
[ROCKSDB_THIS_LAMBDA_CAPTURE]() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunate, but I guess we need it to avoid newer C++ and older C++ disagreeing on which is worth a warning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdillinger Honestly, it we can discusse about it. I have another way to fix it :
- Use the [=, this] everywhere, which is the new way to handle such pattern
- Ignore warning on pre std 20 compilers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this time, we write C++11 with warnings as errors. We aren't going to use a patchwork of trying to ignore this specific warning for various compilers in our default configuration. (I haven't even found a way to turn it off in gcc while keeping -Werror.)
Exactly which C++20 compiler are you getting an error with? I tried latest gcc, clang and msvc on godbolt.org and was not able to get even a warning. Can't you suppress in the C++20 case? (deprecated != removed)
https://godbolt.org/z/8NCWeL
https://godbolt.org/z/2eygL_
https://godbolt.org/z/gPKt3s (see also https://developercommunity.visualstudio.com/content/problem/749985/msvc-1922-emitts-c4626-warning-on-simple-lambdas-w.html)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pdillinger
With gcc 9 -std=c++11: https://godbolt.org/z/Z2DrYm
With gcc 9 -std=c++2a: https://godbolt.org/z/knfpAh
With "-Wno-error=deprecated" it may fix the error and leave the warning, but I don't like it...
On the other hand, I think there is a better (and easier) way : just dop the default capture and capture explicitly. It is cleaner and should work everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Cheng-Chang has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to tweak this because it broke FB's buck integration
Superseded by #6697, which extends this one. Thanks for the valuable contribution! |
|
Summary: Based on #6648 (CLA Signed), but heavily modified / extended: * Implicit capture of this via [=] deprecated in C++20, and [=,this] not standard before C++20 -> now using explicit capture lists * Implicit copy operator deprecated in gcc 9 -> add explicit '= default' definition * std::random_shuffle deprecated in C++17 and removed in C++20 -> migrated to a replacement in RocksDB random.h API * Add the ability to build with different std version though -DCMAKE_CXX_STANDARD=11/14/17/20 on the cmake command line * Minimal rebuild flag of MSVC is deprecated and is forbidden with /std:c++latest (C++20) * Added MSVC 2019 C++11 & MSVC 2019 C++20 in AppVeyor * Added GCC 9 C++11 & GCC9 C++20 in Travis Pull Request resolved: #6697 Test Plan: make check and CI Reviewed By: cheng-chang Differential Revision: D21020318 Pulled By: pdillinger fbshipit-source-id: 12311be5dbd8675a0e2c817f7ec50fa11c18ab91
Summary: Based on facebook/rocksdb#6648 (CLA Signed), but heavily modified / extended: * Implicit capture of this via [=] deprecated in C++20, and [=,this] not standard before C++20 -> now using explicit capture lists * Implicit copy operator deprecated in gcc 9 -> add explicit '= default' definition * std::random_shuffle deprecated in C++17 and removed in C++20 -> migrated to a replacement in RocksDB random.h API * Add the ability to build with different std version though -DCMAKE_CXX_STANDARD=11/14/17/20 on the cmake command line * Minimal rebuild flag of MSVC is deprecated and is forbidden with /std:c++latest (C++20) * Added MSVC 2019 C++11 & MSVC 2019 C++20 in AppVeyor * Added GCC 9 C++11 & GCC9 C++20 in Travis Pull Request resolved: facebook/rocksdb#6697 Test Plan: make check and CI Reviewed By: cheng-chang Differential Revision: D21020318 Pulled By: pdillinger fbshipit-source-id: 12311be5dbd8675a0e2c817f7ec50fa11c18ab91 Signed-off-by: Changlong Chen <levisonchen@live.cn>
Summary: Based on facebook/rocksdb#6648 (CLA Signed), but heavily modified / extended: * Implicit capture of this via [=] deprecated in C++20, and [=,this] not standard before C++20 -> now using explicit capture lists * Implicit copy operator deprecated in gcc 9 -> add explicit '= default' definition * std::random_shuffle deprecated in C++17 and removed in C++20 -> migrated to a replacement in RocksDB random.h API * Add the ability to build with different std version though -DCMAKE_CXX_STANDARD=11/14/17/20 on the cmake command line * Minimal rebuild flag of MSVC is deprecated and is forbidden with /std:c++latest (C++20) * Added MSVC 2019 C++11 & MSVC 2019 C++20 in AppVeyor * Added GCC 9 C++11 & GCC9 C++20 in Travis Pull Request resolved: facebook/rocksdb#6697 Test Plan: make check and CI Reviewed By: cheng-chang Differential Revision: D21020318 Pulled By: pdillinger fbshipit-source-id: 12311be5dbd8675a0e2c817f7ec50fa11c18ab91 Signed-off-by: Changlong Chen <levisonchen@live.cn>
Summary: Based on facebook/rocksdb#6648 (CLA Signed), but heavily modified / extended: * Implicit capture of this via [=] deprecated in C++20, and [=,this] not standard before C++20 -> now using explicit capture lists * Implicit copy operator deprecated in gcc 9 -> add explicit '= default' definition * std::random_shuffle deprecated in C++17 and removed in C++20 -> migrated to a replacement in RocksDB random.h API * Add the ability to build with different std version though -DCMAKE_CXX_STANDARD=11/14/17/20 on the cmake command line * Minimal rebuild flag of MSVC is deprecated and is forbidden with /std:c++latest (C++20) * Added MSVC 2019 C++11 & MSVC 2019 C++20 in AppVeyor * Added GCC 9 C++11 & GCC9 C++20 in Travis Pull Request resolved: facebook/rocksdb#6697 Test Plan: make check and CI Reviewed By: cheng-chang Differential Revision: D21020318 Pulled By: pdillinger fbshipit-source-id: 12311be5dbd8675a0e2c817f7ec50fa11c18ab91 Signed-off-by: Changlong Chen <levisonchen@live.cn>
Summary: Based on facebook/rocksdb#6648 (CLA Signed), but heavily modified / extended: * Implicit capture of this via [=] deprecated in C++20, and [=,this] not standard before C++20 -> now using explicit capture lists * Implicit copy operator deprecated in gcc 9 -> add explicit '= default' definition * std::random_shuffle deprecated in C++17 and removed in C++20 -> migrated to a replacement in RocksDB random.h API * Add the ability to build with different std version though -DCMAKE_CXX_STANDARD=11/14/17/20 on the cmake command line * Minimal rebuild flag of MSVC is deprecated and is forbidden with /std:c++latest (C++20) * Added MSVC 2019 C++11 & MSVC 2019 C++20 in AppVeyor * Added GCC 9 C++11 & GCC9 C++20 in Travis Pull Request resolved: facebook/rocksdb#6697 Test Plan: make check and CI Reviewed By: cheng-chang Differential Revision: D21020318 Pulled By: pdillinger fbshipit-source-id: 12311be5dbd8675a0e2c817f7ec50fa11c18ab91 Signed-off-by: Changlong Chen <levisonchen@live.cn>
Summary: Based on facebook/rocksdb#6648 (CLA Signed), but heavily modified / extended: * Implicit capture of this via [=] deprecated in C++20, and [=,this] not standard before C++20 -> now using explicit capture lists * Implicit copy operator deprecated in gcc 9 -> add explicit '= default' definition * std::random_shuffle deprecated in C++17 and removed in C++20 -> migrated to a replacement in RocksDB random.h API * Add the ability to build with different std version though -DCMAKE_CXX_STANDARD=11/14/17/20 on the cmake command line * Minimal rebuild flag of MSVC is deprecated and is forbidden with /std:c++latest (C++20) * Added MSVC 2019 C++11 & MSVC 2019 C++20 in AppVeyor * Added GCC 9 C++11 & GCC9 C++20 in Travis Pull Request resolved: facebook/rocksdb#6697 Test Plan: make check and CI Reviewed By: cheng-chang Differential Revision: D21020318 Pulled By: pdillinger fbshipit-source-id: 12311be5dbd8675a0e2c817f7ec50fa11c18ab91 Signed-off-by: Changlong Chen <levisonchen@live.cn>
Any interest ?