Skip to content

Commit

Permalink
Merge bitcoin#30633: Fixes for GCC 15 compatibility
Browse files Browse the repository at this point in the history
055bc05 policy/feerate.h: avoid constraint self-dependency (Matt Whitlock)
138f867 add missing #include <cstdint> for GCC 15 (Matt Whitlock)

Pull request description:

  bitcoin#30612 with changes made.

  GCC 15 introduces three build failures:

  * Two are related to missing includes. You can't use `uint16_t` et al. without including `<cstdint>`.

  * The third is harder to understand but easy to fix. GCC changed something about the way templates are instantiated when checking type constraints, and now there is a dependency loop while checking `std::optional<CFeeRate>`. This manifests as the following compile-time mess:
      ```
      In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/format:48,
                       from /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/bits/chrono_io.h:39,
                       from /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/chrono:3362,
                       from ./util/time.h:9,
                       from ./primitives/block.h:12,
                       from ./blockencodings.h:8,
                       from blockencodings.cpp:5:
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/type_traits: In substitution of 'template<class _Up>  requires !(is_same_v<std::optional<_Tp>, typename std::remove_cvref<_It2>::type>) && (is_constructible_v<_Tp, const _Up&>) && (__construct_from_contained_value<_Up, typename std::remove_cv< <template-parameter-1-1> >::type>) constexpr std::optional<CFeeRate>::optional(const std::optional<_Tp>&) [with _Up = CFeeRate]':
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/type_traits:1140:25:   required by substitution of 'template<class _Tp, class ... _Args> using std::__is_constructible_impl = std::__bool_constant<__is_constructible(_Tp, _Args ...)> [with _Tp = CFeeRate; _Args = {std::optional<CFeeRate>&}]'
       1140 |       = __bool_constant<__is_constructible(_Tp, _Args...)>;
            |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/type_traits:1145:12:   required from 'struct std::is_constructible<CFeeRate, std::optional<CFeeRate>&>'
       1145 |     struct is_constructible
            |            ^~~~~~~~~~~~~~~~
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/type_traits:178:35:   required by substitution of 'template<class ... _Bn> std::__detail::__first_t<std::integral_constant<bool, false>, typename std::enable_if<(!(bool)(_Bn::value)), void>::type ...> std::__detail::__or_fn(int) [with _Bn = {std::is_constructible<CFeeRate, std::optional<CFeeRate>&>, std::is_convertible<std::optional<CFeeRate>&, CFeeRate>, std::is_constructible<CFeeRate, std::optional<CFeeRate> >, std::is_convertible<std::optional<CFeeRate>, CFeeRate>, std::is_constructible<CFeeRate, const std::optional<CFeeRate>&>, std::is_convertible<const std::optional<CFeeRate>&, CFeeRate>, std::is_constructible<CFeeRate, const std::optional<CFeeRate> >, std::is_convertible<const std::optional<CFeeRate>, CFeeRate>}]'
        178 |                                      __enable_if_t<!bool(_Bn::value)>...>;
            |                                                               ^~~~~
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/type_traits:196:41:   required from 'struct std::__or_<std::is_constructible<CFeeRate, std::optional<CFeeRate>&>, std::is_convertible<std::optional<CFeeRate>&, CFeeRate>, std::is_constructible<CFeeRate, std::optional<CFeeRate> >, std::is_convertible<std::optional<CFeeRate>, CFeeRate>, std::is_constructible<CFeeRate, const std::optional<CFeeRate>&>, std::is_convertible<const std::optional<CFeeRate>&, CFeeRate>, std::is_constructible<CFeeRate, const std::optional<CFeeRate> >, std::is_convertible<const std::optional<CFeeRate>, CFeeRate> >'
        196 |     : decltype(__detail::__or_fn<_Bn...>(0))
            |                ~~~~~~~~~~~~~~~~~~~~~~~~~^~~
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/optional:824:45:   required from 'constexpr const bool std::optional<CFeeRate>::__construct_from_contained_value<CFeeRate, CFeeRate>'
        824 |           = !__converts_from_optional<_Tp, _From>::value;
            |                                                    ^~~~~
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/optional:884:7:   required by substitution of 'template<class _Up>  requires !(is_same_v<std::optional<_Tp>, typename std::remove_cvref<_It2>::type>) && (is_constructible_v<_Tp, const _Up&>) && (__construct_from_contained_value<_Up, typename std::remove_cv< <template-parameter-1-1> >::type>) constexpr std::optional<CFeeRate>::optional(const std::optional<_Tp>&) [with _Up = CFeeRate]'
        884 |           && __construct_from_contained_value<_Up>
            |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ./validation.h:164:41:   required from here
        164 |         return MempoolAcceptResult(state);
            |                                         ^
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/optional:886:2:   required by the constraints of 'template<class _Tp> template<class _Up>  requires !(is_same_v<std::optional<_Tp>, typename std::remove_cvref<_It2>::type>) && (is_constructible_v<_Tp, const _Up&>) && (__construct_from_contained_value<_Up, typename std::remove_cv< <template-parameter-1-1> >::type>) constexpr std::optional<_Tp>::optional(const std::optional<_From>&)'
      /usr/lib/gcc/x86_64-pc-linux-gnu/15/include/g++-v15/optional:884:14: error: satisfaction of atomic constraint '__construct_from_contained_value<_Up, typename std::remove_cv< <template-parameter-1-1> >::type> [with _Tp = _Tp; _Up = _Up]' depends on itself
        884 |           && __construct_from_contained_value<_Up>
            |              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ```
      It is easiest to solve this by changing the `static_assert` in the explicit `CFeeRate` constructor to a SFINAE by using a type constraint on the function template parameter.

  We already [downstreamed](gentoo/gentoo#38015) these fixes in Gentoo.

ACKs for top commit:
  stickies-v:
    ACK 055bc05

Tree-SHA512: ce9cb27bcd9b0f4bbc80951e45cf7127112dcb7f9937bcb0167b362026d35beecb1255354746de0aac82e03c41eaccbe26acbfe0ddff2ee1e5a8634673f4f4ba
  • Loading branch information
fanquake committed Aug 12, 2024
2 parents 4c879c4 + 055bc05 commit 012baa4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/chainparamsbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <util/chaintype.h>

#include <cstdint>
#include <memory>
#include <string>

Expand Down
3 changes: 2 additions & 1 deletion src/node/interface_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
#ifndef BITCOIN_NODE_INTERFACE_UI_H
#define BITCOIN_NODE_INTERFACE_UI_H

#include <cstdint>
#include <functional>
#include <memory>
#include <string>
#include <vector>

class CBlockIndex;
enum class SynchronizationState;
Expand Down
4 changes: 1 addition & 3 deletions src/policy/feerate.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ class CFeeRate
public:
/** Fee rate of 0 satoshis per kvB */
CFeeRate() : nSatoshisPerK(0) { }
template<typename I>
template<std::integral I> // Disallow silent float -> int conversion
explicit CFeeRate(const I _nSatoshisPerK): nSatoshisPerK(_nSatoshisPerK) {
// We've previously had bugs creep in from silent double->int conversion...
static_assert(std::is_integral<I>::value, "CFeeRate should be used without floats");
}

/**
Expand Down

0 comments on commit 012baa4

Please sign in to comment.