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

Fix compilation with GCC9 and MSVC 2019 with CMAKE_CXX_STANDARD=20 #6648

Closed
wants to merge 12 commits into from
Closed

Fix compilation with GCC9 and MSVC 2019 with CMAKE_CXX_STANDARD=20 #6648

wants to merge 12 commits into from

Conversation

syoliver
Copy link

@syoliver syoliver commented Apr 5, 2020

  • Add the ability to build with different std version though -DCMAKE_CXX_STANDARD=11/14/17/20 on the cmake command line
  • Implicit capture of this via [=] deprecated in C++20
  • Implicity copy operator deprecated in gcc 9
  • std::random_shuffle deprecated in C++17 and removed in C++20
  • Minimal rebuild flag of MSVC is deprectaed 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++30 in Travis

Any interest ?

@adamretter
Copy link
Collaborator

@syoliver Are these changes still compatible with VS 2015?

@syoliver
Copy link
Author

syoliver commented Apr 6, 2020

@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 :-(

@adamretter
Copy link
Collaborator

@syoliver As long as AppVeyor for VS2015 passes then I am a happy person :-)

@syoliver
Copy link
Author

syoliver commented Apr 7, 2020

Timeout reached in travis, but it seems to work.
Is it interesting ? Any comment ?

@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.

@syoliver syoliver marked this pull request as ready for review April 7, 2020 08:15
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

@ghost ghost requested a review from pdillinger April 10, 2020 17:34
@facebook-github-bot
Copy link
Contributor

@syoliver has updated the pull request. Re-import the pull request

@facebook-github-bot
Copy link
Contributor

@syoliver has updated the pull request. Re-import the pull request

Copy link
Contributor

@pdillinger pdillinger left a 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;
Copy link
Contributor

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.

Copy link
Author

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]() {
Copy link
Contributor

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

Copy link
Author

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

Copy link
Contributor

@pdillinger pdillinger Apr 13, 2020

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)

Copy link
Author

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.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a 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.

Copy link
Contributor

@pdillinger pdillinger left a 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

@pdillinger pdillinger mentioned this pull request Apr 14, 2020
@pdillinger
Copy link
Contributor

Superseded by #6697, which extends this one. Thanks for the valuable contribution!

@pdillinger pdillinger closed this Apr 14, 2020
@syoliver
Copy link
Author

Superseded by #6697, which extends this one. Thanks for the valuable contribution!
Thank you @pdillinger great job :-)

facebook-github-bot pushed a commit that referenced this pull request Apr 20, 2020
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
levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 18, 2021
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>
levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 18, 2021
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>
mm304321141 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 23, 2021
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>
levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Jun 24, 2021
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>
levichen94 pushed a commit to bytedance/terarkdb that referenced this pull request Sep 14, 2021
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants