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

Update C++ standard to 14 and clean up #19490

Merged
merged 5 commits into from Dec 16, 2017
Merged

Conversation

adamemerson
Copy link
Contributor

Still an improvement!

#ifndef CEPH_COMMON_BACKPORT14_H
#define CEPH_COMMON_BACKPORT14_H

// Library code from C++14 that can be implemented in C++11.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this comment can be updated

using remove_reference_t = typename std::remove_reference<T>::type;
template<typename T>
using result_of_t = typename std::result_of<T>::type;
// Template variable aliases from C++17 <type_traits>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we guard this with #if __cplusplus < 201703L, and just put these templates into namespace std?

@adamemerson
Copy link
Contributor Author

@tchaikov Maaaaybe? It's Undefined Behavior and Bad and Naughty and so I'd rather not, but it would probably work.

I have a /better/ solution for this sort of problem I've been working on from time to time.

Generally, if we put everything in core inside the ceph namespace

And encapsulated things like this in a few inline namespaces so we could easily pull them into RGW and RBD and whatnot

Then we could easily change definitions to usings and things like that, but it's a fairly large project and I haven't had a chance to work on it recently.

@cbodley
Copy link
Contributor

cbodley commented Dec 13, 2017

It's Undefined Behavior and Bad and Naughty and so I'd rather not

that's my feeling as well. it might make our transitions between c++ versions a bit easier, but i don't think we do that often enough to get so adventurous

@adamemerson
Copy link
Contributor Author

Yeah, once we go to 17, whenever the CentOS people get their thing done, we won't have to change this sort of thing until …2020?

Copy link
Contributor

@tchaikov tchaikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamemerson @cbodley makes sense to me!

Fix a couple problems.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
@adamemerson
Copy link
Contributor Author

@tchaikov One minor error crept in during a rebase, just fixed it.

@adamemerson
Copy link
Contributor Author

Well, major in that it broke everything, but minor in terms of scope and fix and complexity.

template<typename T>
using remove_reference_t = typename std::remove_reference<T>::type;
template<typename T>
using result_of_t = typename std::result_of<T>::type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In file included from /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/dout.h:22:0,
                 from /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/debug.h:18,
                 from /home/jenkins-build/build/workspace/ceph-pull-requests/src/compressor/Compressor.cc:22:
/home/jenkins-build/build/workspace/ceph-pull-requests/src/common/config.h:171:11: error: 'result_of_t' in namespace 'ceph' does not name a template type
     ceph::result_of_t<Callback(const T&, Args...)> {
           ^~~~~~~~~~~
/home/jenkins-build/build/workspace/ceph-pull-requests/src/common/config.h:171:22: error: expected initializer before '<' token
     ceph::result_of_t<Callback(const T&, Args...)> {
                      ^
src/compressor/CMakeFiles/compressor_objs.dir/build.make:62: recipe for target 'src/compressor/CMakeFiles/compressor_objs.dir/Compressor.cc.o' failed

@adamemerson

@@ -14,7 +14,7 @@
*
*/

#include "common/backport14.h" // include first: tests that header is standalone
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C++14 provides the ability to define template variables, which the C++17
library puts to good use. We define those same aliases.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
@adamemerson
Copy link
Contributor Author

Oops. My own merged patch did me in. Fixed and pushed. Will run a local compile to check anything else.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
Since we're on C++14, we're just backporting from future standards
generally.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
@adamemerson
Copy link
Contributor Author

@tchaikov All right, got the problems I introduced by rebasing cleared away.

@tchaikov tchaikov merged commit 419a182 into ceph:master Dec 16, 2017
@cbodley
Copy link
Contributor

cbodley commented Dec 18, 2017

exciting! 🎉 you are my heroes, @tchaikov and @adamemerson!

@chardan
Copy link
Contributor

chardan commented Dec 18, 2017

Very cool!!

@adamemerson adamemerson deleted the wip-hypomodern branch December 20, 2017 23:03
@theanalyst
Copy link
Member

Awesome!

@smithfarm
Copy link
Contributor

smithfarm commented Sep 2, 2019

@adamemerson @chardan Could you help me diagnose the build failure we are seeing in nautilus? Here are some instances of it:

#30040
#30049
#30050

It blurts out a gazillion errors, but the first one is:

/home/jenkins-build/build/workspace/ceph-pull-requests/src/common/convenience.h:46:24: error: 'result_of_t' is not a member of 'std'
   boost::optional<std::result_of_t<F(const std::decay_t<T>)>>

which would appear to be related to this PR?

Also, at https://en.cppreference.com/w/cpp/types/result_of I saw that this feature added by C++14 is now deprecated and due to be removed in C++20... not sure what should be done (if anything) about that.

@smithfarm
Copy link
Contributor

smithfarm commented Sep 2, 2019

@tchaikov Looks like "make check" is broken in nautilus? (See the previous comment - all of the "make check" failures in nautilus seem to be caused by this same issue, i.e. ostensibly "'result_of_t' is not a member of 'std'"...)

@tchaikov
Copy link
Contributor

tchaikov commented Sep 2, 2019

@smithfarm thanks for looking into this. yeah, i am afraid "rëtest this please" won't work this time. will investigate this early tomorrow.

@chardan
Copy link
Contributor

chardan commented Sep 2, 2019

@smithfarm Yeah, for C++17 result_of was deprecated, and removed in C++20 (see the "resolved issues" section here: https://tinyurl.com/km5tkhu). Chances are good that you can just replace it with "std::invoke_result" and "std::invoke_result_t".

@chardan
Copy link
Contributor

chardan commented Sep 2, 2019

I also saw the earlier part of the conversation related to feature testing, and wanted to point out that there are lots of new feature-test macros made available:
https://en.cppreference.com/w/cpp/feature_test
...and a good article from Study Group 10 on using them:
https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations

@tchaikov
Copy link
Contributor

tchaikov commented Sep 3, 2019

@smithfarm i failed to reproduce the FTBFS in my own xenial container and in #30083 . the only thing i can think of is to use GCC-8. see #30089.

but i think the root cause is still unknown. as the error message put

/home/jenkins-build/build/workspace/ceph-pull-requests/src/common/ceph_time.h:504:16: warning: variable templates only available with -std=c++14 or -std=gnu++14
 constexpr bool converts_to_timespec_v = converts_to_timespec<Clock>::value;
                ^~~~~~~~~~~~~~~~~~~~~~

and we do pass -std=c++17 to g++. see

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

@cbodley
Copy link
Contributor

cbodley commented Sep 3, 2019

in the VERBOSE output, i see that an extra -std=gnu++11 is getting sprinkled into some targets after the -std=c++17. is it possible that cmake is getting confused by the set(CMAKE_CXX_STANDARD 11)s in src/dmclock/CMakeLists.txt and src/fmt/support/cmake/cxx14.cmake? on master, we have set(CMAKE_CXX_STANDARD 17), but here we're just adding -std=c++17 to CMAKE_CXX_FLAGS

@tchaikov
Copy link
Contributor

tchaikov commented Sep 3, 2019

@cbodley thanks a lot! that explains. i ran into the same issue couple weeks ago before switching over to cmake 3.10.

i believe that's the root cause.

@tchaikov
Copy link
Contributor

tchaikov commented Sep 3, 2019

but we need to either use cmake 3.10 for addressing this issue or hack libfmt to prevent it from falling back to C++11.

@cbodley
Copy link
Contributor

cbodley commented Sep 3, 2019

what do we need from cmake 3.10? is that what adds 17 as an option for CXX_STANDARD?

@tchaikov
Copy link
Contributor

tchaikov commented Sep 3, 2019

yeah, 3.8 introduced the support of CXX_STANDARD=17.

@tchaikov
Copy link
Contributor

tchaikov commented Sep 3, 2019

i am working on a fix for libfmt and dmclock.

@tchaikov
Copy link
Contributor

tchaikov commented Sep 3, 2019

#30113 #30114

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants