Skip to content

Commit

Permalink
[cpp] move to C++17
Browse files Browse the repository at this point in the history
Summary:
Debian buster ships with gcc 7/8 which is all green according to:
https://gcc.gnu.org/projects/cxx-status.html

Depends on D8492 and D8495

edit: backported some changes from Core [[bitcoin/bitcoin#18591 | PR18591]] regarding implicit conversion between Span types

Test Plan:
  ninja all check
  test_runner.py --extended

Reviewers: #bitcoin_abc, Fabien, deadalnix

Reviewed By: #bitcoin_abc, Fabien, deadalnix

Subscribers: deadalnix, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D8493
  • Loading branch information
majcosta committed Nov 23, 2020
1 parent 65d3380 commit 1541dc4
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion arcanist/linter/CppCheckLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ final class CppCheckLinter extends ArcanistExternalLinter {
'-j2',
'--enable=all',
'--language=c++',
'--std=c++14',
'--std=c++17',
);

const CPPCHECK_DEFINITIONS = array(
Expand Down
2 changes: 1 addition & 1 deletion doc/build-osx.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ If you want to build the disk image with `ninja osx-dmg` (.dmg / optional), you
Build Bitcoin ABC
-----------------

Before you start building, please make sure that your compiler supports C++14.
Before you start building, please make sure that your compiler supports C++17.

1. Clone the Bitcoin ABC source code and cd into `bitcoin-abc`

Expand Down
2 changes: 1 addition & 1 deletion doc/build-unix.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Some notes on how to build Bitcoin ABC in Unix.
To Build
---------------------

Before you start building, please make sure that your compiler supports C++14.
Before you start building, please make sure that your compiler supports C++17.

It is recommended to create a build directory to build out-of-tree.

Expand Down
2 changes: 1 addition & 1 deletion doc/build-windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Other options which may work, but which have not been extensively tested are (pl
* On Windows, using a POSIX compatibility layer application such as [cygwin](http://www.cygwin.com/) or [msys2](http://www.msys2.org/).
* On Windows, using a native compiler tool chain such as [Visual Studio](https://www.visualstudio.com).

In any case please make sure that the compiler supports C++14.
In any case please make sure that the compiler supports C++17.

Installing Windows Subsystem for Linux
---------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions doc/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ These are the dependencies currently used by Bitcoin ABC. You can find instructi
| --- | --- | --- | --- | --- | --- |
| Berkeley DB | [5.3.28](http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/downloads/index.html) | 5.3 | No | | |
| Boost | [1.70.0](https://www.boost.org/users/download/) | 1.59.0 | No | | |
| Clang | | [3.4](https://releases.llvm.org/download.html) (C++14 support) | | | |
| Clang | | [5](https://releases.llvm.org/download.html) (C++17 support) | | | |
| CMake | | [3.16](https://cmake.org/download/) | | | |
| Expat | [2.2.7](https://libexpat.github.io/) | | No | Yes | |
| fontconfig | [2.12.6](https://www.freedesktop.org/software/fontconfig/release/) | | No | Yes | |
| FreeType | [2.7.1](http://download.savannah.gnu.org/releases/freetype) | | No | | |
| GCC | | [5.0](https://gcc.gnu.org/) (C++14 support) | | | |
| GCC | | [7](https://gcc.gnu.org/) (C++17 support) | | | |
| HarfBuzz-NG | | | | | |
| jemalloc | [5.2.1](https://github.com/jemalloc/jemalloc/releases) | 3.6.0 | | | |
| libevent | [2.1.11-stable](https://github.com/libevent/libevent/releases) | 2.0.22 | No | | |
Expand Down
2 changes: 2 additions & 0 deletions doc/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Bitcoin ABC version 0.22.8 is now available from:
<https://download.bitcoinabc.org/0.22.8/>

This release includes the following features and fixes:

- Code updated to conform to the C++17 standard.
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

project(bitcoind)

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Default visibility is hidden on all targets.
set(CMAKE_C_VISIBILITY_PRESET hidden)
Expand Down
4 changes: 2 additions & 2 deletions src/compat/assumptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#error "Bitcoin cannot be compiled without assertions."
#endif

// Assumption: We assume a C++14 (ISO/IEC 14882:2014) compiler (minimum
// Assumption: We assume a C++17 (ISO/IEC 14882:2017) compiler (minimum
// requirement).
// Example(s): We use std::make_unique() through the codebase.
// Note: MSVC does not report the expected __cplusplus value due to
Expand All @@ -29,7 +29,7 @@
// N3936* §16.8 [cpp.predefined]/p1::
// "The name __cplusplus is defined to the value 201402L when compiling a C++
// translation unit."
static_assert(__cplusplus >= 201402L, "C++14 standard assumed");
static_assert(__cplusplus >= 201703L, "C++17 standard assumed");
#endif

// Assumption: We assume the floating-point types to fulfill the requirements of
Expand Down
24 changes: 24 additions & 0 deletions src/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ template <typename C> class Span {
constexpr Span(C *data, C *end) noexcept
: m_data(data), m_size(end - data) {}

/** Implicit conversion of spans between compatible types.
*
* Specifically, if a pointer to an array of type O can be implicitly
* converted to a pointer to an array of type C, then permit implicit
* conversion of Span<O> to Span<C>. This matches the behavior of the
* corresponding C++20 std::span constructor.
*
* For example this means that a Span<T> can be converted into a Span<const
* T>.
*/
template <typename O,
typename std::enable_if<
std::is_convertible<O (*)[], C (*)[]>::value, int>::type = 0>
constexpr Span(const Span<O> &other) noexcept
: m_data(other.m_data), m_size(other.m_size) {}

/** Default copy constructor. */
constexpr Span(const Span &) noexcept = default;

/** Default assignment operator. */
Span &operator=(const Span &other) noexcept = default;

constexpr C *data() const noexcept { return m_data; }
constexpr C *begin() const noexcept { return m_data; }
constexpr C *end() const noexcept { return m_data + m_size; }
Expand Down Expand Up @@ -69,6 +91,8 @@ template <typename C> class Span {
friend constexpr bool operator>=(const Span &a, const Span &b) noexcept {
return !(a < b);
}

template <typename O> friend class Span;
};

/** Create a span to a container exposing data() and size().
Expand Down

0 comments on commit 1541dc4

Please sign in to comment.