Skip to content

Discussion: upgrading to C++17 #16684

Closed
Closed

Description

@dongcarl

UPDATE: Release plan summary from April 2nd, 2020 meeting:

C++11 Compat C++17 Compat Gitian/Guix Release
v0.20 ✔️ if easy C++11
v0.21 ✔️ ✔️ C++17
v0.22 ❌ ✔️ C++17

Meeting logs can be found here: http://www.erisian.com.au/meetbot/bitcoin-core-dev/2020/bitcoin-core-dev.2020-04-02-19.01.log.html


There were some discussion around upgrading to C++17. It seems to be able to give us library and language features that will simplify future code. For example, for library features, our current optional.h is just a wrapper around boost::optional, and can be replaced with std::optional. Other library features that might be useful include (non-exhaustively): std::variant, the file system library, and std::shared_mutex. @elichai has kindly provided a table summarizing features useful for Bitcoin Core here: #16684 (comment).

I want to apologize for misspeaking about C++17 requiring GCC8, that is untrue, and I believe all of the features we would want will be covered by GCC7, and some by GCC6.

For some background on the cons: #13356 (comment)


Default GCC versions major distros (as of Aug 22nd):

Operating System release version GCC version Notes
✔️ Debian Buster 8.3
✔️ Ubuntu 18.04 LTS 7.4
✔️ Fedora 30 9.1.1
✔️ RHEL 8 8.2
CentOS 7 4.8.5 CentOS 8 (GCC 8.2) is being released as we speak

In-depth code examples of

C++17 features: https://github.com/AnthonyCalandra/modern-cpp-features/blob/master/CPP17.md
C++14 features: https://github.com/AnthonyCalandra/modern-cpp-features/blob/master/CPP14.md


Here are some compatibility tables from https://en.cppreference.com/w/cpp/compiler_support#cpp17

Library features:
Screen Shot 2019-08-22 at 19 39 24

Language features:
Screen Shot 2019-08-22 at 19 38 32

Activity

  1. practicalswift commented on Aug 22, 2019

    @practicalswift
    Contributor

    Some C++14 features worth mentioning as well: std::make_unique, more expressive constexpr functions allowed, return type deduction (auto foo() { … }), [[deprecated]], binary literals (0b10101110) and polymorphic lambdas ([](auto foo) { … }).

  2. elichai commented on Aug 22, 2019

    @elichai
    Contributor

    A table on features in C++14/17 which I think would be very useful (feel free to comment if you disagree or think other stuff should be added)

    Name Important Nice to have Boost Replacement
    std::variant ✔️
    std::make_unique ✅
    Variable Templates ✅
    Conditions in constexpr functions ✔️
    auto in lambdas params ✅
    Binary literals ✔️
    std::filesystem ✔️ ✔️
    std::optional ✔️
    [[nodiscard]]+[[fallthrough]] ✔️
    de-structuring initialization ✅
    shared_mutex + scoped_lock + shared_lock ✅ ✔️
  3. elichai commented on Oct 3, 2019

    @elichai
    Contributor

    Another reason we might want to upgrade:
    very powerful const expressions. both c++14 and 17 made constexpr way more powerfull.
    such that we could start making a lot of functions constexpr which might maybe result in some performance increase (for functions that might be able to be evaluated at compile time)

  4. maflcko commented on Oct 3, 2019

    @maflcko
    Member

    Is C++17 supported on Ubuntu Xenial, Debian 9, and the *BSD operating systems?

  5. ysangkok commented on Oct 3, 2019

    @ysangkok

    Debian 9 ships GCC 6.3 according to the development packages listing. GCC 6 is listed as supporting some features of C++17 experimentally.

    Ubuntu Xenial ships with a default GCC 5.3, which is even older. A PPA offers newer GCC versions: ~ubuntu-toolchain-r

  6. added this to the 0.21.0 milestone on Dec 9, 2019
  7. laanwj commented on Dec 9, 2019

    @laanwj
    Member

    Added 0.21 milestone optimistically

  8. sanjaykdragon commented on Jan 3, 2020

    @sanjaykdragon
    Contributor

    I agree with moving to C++17, but when do we plan to move to the soon coming C++20?

  9. sipa commented on Jan 3, 2020

    @sipa
    Member

    @sanjaykdragon It's not that easy, as we need to remain compatible with various stable Linux distributions, which don't update their C++ compilers that frequently (or at all, after release of a particular distro version).

    C++20 does not exist yet, so that seems entirely out of scope.

  10. sanjaykdragon commented on Jan 3, 2020

    @sanjaykdragon
    Contributor

    @sanjaykdragon It's not that easy, as we need to remain compatible with various stable Linux distributions, which don't update their C++ compilers that frequently (or at all, after release of a particular distro version).

    C++20 does not exist yet, so that seems entirely out of scope.

    Are we just waiting for linux distributions to become compatible with C++17 for a migration?

  11. practicalswift commented on Jan 9, 2020

    @practicalswift
    Contributor

    Of the 13 build jobs we have in Travis it looks like three build jobs use compilers without C++17 support: CentOS 7, Ubuntu 16.04 (Xenial) and macOS Sierra (10.12). Sounds correct? :)

  12. laanwj commented on Jan 13, 2020

    @laanwj
    Member

    Are we just waiting for linux distributions to become compatible with C++17 for a migration?

    Yes, that's the main factor holding it up.

  13. sanjaykdragon commented on Jan 30, 2020

    @sanjaykdragon
    Contributor

    Just a comment / improvement to make when we move to C++17:
    use std::string_view more.

  14. practicalswift commented on Jan 30, 2020

    @practicalswift
    Contributor

    @sanjaykdragon std::string_view has really sharp edges with regards to life-time -- some would even claim it encourages use-after-free bugs.

    I think our recommendation should be to try to avoid std::string_view in the general case, and use it only in places where it is both a.) needed for performance reasons (as demonstrated by benchmarks), and b.) guaranteed to be safe :)

  15. 22 remaining items

  16. ysangkok commented on Nov 12, 2020

    @ysangkok

    @theuni The bugzilla link you posted is for bug 23861. But the Ubuntu bug you posted links 23844 (a different bug number). I am letting you know since I found it confusing. @MarcoFalke Bug 23844 was deferred from 2.29 according to release notes.

  17. ilyapopov commented on Nov 12, 2020

    @ilyapopov

    @theuni This Ubuntu bug is about Ubuntu 18.04 Bionic.

    Newer versions of Ubuntu, such as 20.04 LTS and 20.10 already have had the fixed version from the beginning.

  18. added a commit that references this issue on Nov 19, 2020
  19. maflcko commented on Nov 20, 2020

    @maflcko
    Member

    Closing this for now. If discussions about specific features are needed, they should go to #20419 or #19183 or whatever pull request proposes them.

  20. maflcko commented on Nov 23, 2020

    @maflcko
    Member

    std::fs discussion here: #20460

  21. ysangkok commented on Jan 15, 2021

    @ysangkok

    @MarcoFalke How old do the patched glibc version need to be before it can be assumed present? Glibc 2.30 which contains fixes for bugs 23861 and 23844 was released in August 2019, and backports are available. The bugs only affect users running old distros without updating.

  22. fanquake commented on Jan 15, 2021

    @fanquake
    Member

    The bugs only affect users running old distros without updating.

    Ubuntu Bionic (18.04LTS) ships with glibc 2.27 and will remain supported until April 2023.

  23. ysangkok commented on Jan 15, 2021

    @ysangkok

    Bionic (18.04LTS) ships glibc 2.27

    @fanquake Yes, but it received a backported fix as shown in the Launchpad link. All users have -updates enabled by default, so the only way you could miss it is if you didn't run apt upgrade since November. Does Core need to cater to that tiny minority that runs an LTS release but does not keep it updated? You can only use Bitcoin if you are internet-connected anyway, so what is the rationale for being internet-connected, but keeping your system buggy and vulnerable (other fixes could be more severe)?

  24. locked as resolved and limited conversation to collaborators on Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions