Skip to content

fix: make conversion to address explicit#487

Merged
evoskuil merged 1 commit into
libbitcoin:masterfrom
josibake:upstream-patch
Jun 26, 2025
Merged

fix: make conversion to address explicit#487
evoskuil merged 1 commit into
libbitcoin:masterfrom
josibake:upstream-patch

Conversation

@josibake

Copy link
Copy Markdown
Contributor

When building on macOS via nix, I get the following error:

Running phase: unpackPhase
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking source archive /nix/store/70kic1gxwz3z2krkd59sk1l2a50r3djx-source
source root is source
Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: autoreconfPhase
@nix { "action": "setPhase", "phase": "autoreconfPhase" }
autoreconf: export WARNINGS=
autoreconf: Entering directory '.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force -I m4
autoreconf: configure.ac: tracing
autoreconf: configure.ac: creating directory build-aux
autoreconf: running: libtoolize --copy --force
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'build-aux'.
libtoolize: copying file 'build-aux/ltmain.sh'
libtoolize: putting macros in AC_CONFIG_MACRO_DIRS, 'm4'.
libtoolize: copying file 'm4/libtool.m4'
libtoolize: copying file 'm4/ltoptions.m4'
libtoolize: copying file 'm4/ltsugar.m4'
libtoolize: copying file 'm4/ltversion.m4'
libtoolize: copying file 'm4/lt~obsolete.m4'
autoreconf: configure.ac: not using Intltool
autoreconf: configure.ac: not using Gtkdoc
autoreconf: running: aclocal --force -I m4
autoreconf: running: /nix/store/ya954fbyialirl4dbxqwmyl4sf9k6rzb-autoconf-2.72/bin/autoconf --force
autoreconf: configure.ac: not using Autoheader
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac:36: installing 'build-aux/ar-lib'
configure.ac:36: installing 'build-aux/compile'
configure.ac:42: installing 'build-aux/config.guess'
configure.ac:42: installing 'build-aux/config.sub'
configure.ac:30: installing 'build-aux/install-sh'
configure.ac:30: installing 'build-aux/missing'
Makefile.am: installing 'build-aux/depcomp'
parallel-tests: installing 'build-aux/test-driver'
autoreconf: 'build-aux/install-sh' is updated
autoreconf: Leaving directory '.'
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Updating Autotools / GNU config script to a newer upstream version: ./build-aux/config.sub
Updating Autotools / GNU config script to a newer upstream version: ./build-aux/config.guess
Running phase: configurePhase
@nix { "action": "setPhase", "phase": "configurePhase" }
fixing libtool script ./build-aux/ltmain.sh
./configure
patching script interpreter paths in ./configure
./configure: interpreter directive changed from "#! /bin/sh" to "/nix/store/8ivrpmp3arvxbr6imdwm2d28q9cjsqvi-bash-5.2p37/bin/sh"
configure flags: --disable-static --disable-dependency-tracking --prefix=/nix/store/xyz8f8h0hwdh7pa52rlwmayn7px35hs7-libbitcoin-networ>
checking for a BSD-compatible install... /nix/store/d72z8b7fvvcin2p84x7h5s0abkggplzc-coreutils-9.7/bin/install -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... /nix/store/d72z8b7fvvcin2p84x7h5s0abkggplzc-coreutils-9.7/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports the include directive... yes (GNU style)
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C++... yes
checking whether clang++ accepts -g... yes
checking for clang++ option to enable C++11 features... none needed
checking dependency style of clang++... none
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for wchar.h... yes
checking for minix/config.h... no
checking whether it is safe to define __EXTENSIONS__... yes
checking whether _XOPEN_SOURCE should be defined... no
checking for gcc... clang
checking whether the compiler supports GNU C... yes
checking whether clang accepts -g... yes
checking for clang option to enable C11 features... none needed
checking whether clang understands -c and -o together... yes
checking dependency style of clang... none
checking the archiver (ar) interface... ar
checking build system type... aarch64-apple-darwin24.4.0
checking host system type... aarch64-apple-darwin24.4.0
checking how to print strings... printf
checking for a sed that does not truncate output... /nix/store/3p81h24g11jfcdd7ifql71lr5mjag102-gnused-4.9/bin/sed
checking for grep that handles long lines and -e... /nix/store/6rdq4hg48bmqy7d8da38niai5ngg1x1s-gnugrep-3.11/bin/grep
checking for egrep... /nix/store/6rdq4hg48bmqy7d8da38niai5ngg1x1s-gnugrep-3.11/bin/grep -E
checking for fgrep... /nix/store/6rdq4hg48bmqy7d8da38niai5ngg1x1s-gnugrep-3.11/bin/grep -F
checking for ld used by clang... ld
checking if the linker (ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... nm
checking the name lister (nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 786432
checking how to convert aarch64-apple-darwin24.4.0 file names to aarch64-apple-darwin24.4.0 format... func_convert_file_noop
checking how to convert aarch64-apple-darwin24.4.0 file names to toolchain format... func_convert_file_noop
checking for ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... (cached) pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ranlib... ranlib
checking for archiver @FILE support... @
checking for strip... strip
checking command to parse nm output from clang object... ok
checking for sysroot... no
checking for a working dd... /nix/store/d72z8b7fvvcin2p84x7h5s0abkggplzc-coreutils-9.7/bin/dd
checking how to truncate binary pipes... /nix/store/d72z8b7fvvcin2p84x7h5s0abkggplzc-coreutils-9.7/bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... no
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -no_fixup_chains linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if clang supports -fno-rtti -fno-exceptions... yes
checking for clang option to produce PIC... -fno-common -DPIC
checking if clang PIC flag -fno-common -DPIC works... yes
checking if clang static flag -static works... no
checking if clang supports -c -o file.o... yes
checking if clang supports -c -o file.o... (cached) yes
checking whether the clang linker (ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin24.4.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking how to run the C++ preprocessor... clang++ -E
checking for ld used by clang++... ld
checking if the linker (ld) is GNU ld... no
checking whether the clang++ linker (ld) supports shared libraries... yes
checking for clang++ option to produce PIC... -fno-common -DPIC
checking if clang++ PIC flag -fno-common -DPIC works... yes
checking if clang++ static flag -static works... no
checking if clang++ supports -c -o file.o... yes
checking if clang++ supports -c -o file.o... (cached) yes
checking whether the clang++ linker (ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin24.4.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether the compiler supports GNU C++... (cached) yes
checking whether clang++ accepts -g... (cached) yes
checking for clang++ option to enable C++11 features... (cached) none needed
checking dependency style of clang++... (cached) none
checking for a sed that does not truncate output... (cached) /nix/store/3p81h24g11jfcdd7ifql71lr5mjag102-gnused-4.9/bin/sed
checking whether make supports nested variables... (cached) yes
checking pkg-config is at least version 0.9.0... yes
checking whether clang++ supports C++20 features with -std=c++20... yes
checking --with-pkgconfigdir option... ${exec_prefix}/lib/pkgconfig
checking --with-tests option... yes
checking --enable-ndebug option... yes
checking --enable-isystem option... no
checking whether C++ compiler accepts -std=c++20... yes
checking whether C++ compiler accepts -Wall... yes
checking whether C++ compiler accepts -Wall... (cached) yes
checking whether C++ compiler accepts -Wextra... yes
checking whether C++ compiler accepts -Wextra... (cached) yes
checking whether C++ compiler accepts -Wno-reorder... yes
checking whether C++ compiler accepts -Wno-missing-field-initializers... yes
checking whether C++ compiler accepts -Wno-missing-braces... yes
checking whether C++ compiler accepts -Wno-comment... yes
checking whether C++ compiler accepts -Wno-deprecated-copy... yes
checking whether C++ compiler accepts -Wno-mismatched-tags... yes
checking whether the linker accepts -no_fixup_chains... no
checking whether the linker accepts -fstack-protector... yes
checking whether the linker accepts -fstack-protector-all... yes
checking for boostlib >= 1.86.0 (108600)... yes
configure: boost_CPPFLAGS :
configure: boost_ISYS_CPPFLAGS :
configure: boost_LDFLAGS : -L/nix/store/8ly7rzckcqdzb90gplbqlgmfpy7ks4k4-boost-1.86.0/lib
configure: boost_BUILD_CPPFLAGS :
checking whether the Boost::Unit_Test_Framework library is available... yes
configure: boost_unit_test_framework_LIBS : -lboost_unit_test_framework
checking for libbitcoin-system >= 4.0.0... yes
configure: bitcoin_system_CPPFLAGS : -I/nix/store/3c4233wk0gq4qlg3ki3qkri9dzpacizh-secp256k1-0.6.0/include -I/nix/store/xx1m8jjhgww56n>
configure: bitcoin_system_ISYS_CPPFLAGS : -isystem/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include
configure: bitcoin_system_OTHER_CFLAGS :
configure: bitcoin_system_INCLUDEDIR : /nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include
configure: bitcoin_system_LIBS : -L/nix/store/3c4233wk0gq4qlg3ki3qkri9dzpacizh-secp256k1-0.6.0/lib -L/nix/store/xx1m8jjhgww56nblbb08vm>
configure: bitcoin_system_BUILD_CPPFLAGS : -I/nix/store/3c4233wk0gq4qlg3ki3qkri9dzpacizh-secp256k1-0.6.0/include -I/nix/store/xx1m8jjh>
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: creating libbitcoin-network.pc
config.status: executing depfiles commands
config.status: executing libtool commands
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
build flags: -j8 SHELL=/nix/store/8ivrpmp3arvxbr6imdwm2d28q9cjsqvi-bash-5.2p37/bin/bash prefix=/nix/store/xyz8f8h0hwdh7pa52rlwmayn7px3>
  CXX      src/libbitcoin_network_la-error.lo
  CXX      src/libbitcoin_network_la-memory.lo
  CXX      src/libbitcoin_network_la-p2p.lo
  CXX      src/libbitcoin_network_la-settings.lo
  CXX      src/async/libbitcoin_network_la-thread.lo
  CXX      src/async/libbitcoin_network_la-threadpool.lo
  CXX      src/async/libbitcoin_network_la-time.lo
  CXX      src/config/libbitcoin_network_la-address.lo
src/config/address.cpp:62:13: error: no viable conversion from 'endpoint' to 'address'
   62 |   : address(endpoint{ uri })
      |             ^~~~~~~~~~~~~~~
./include/bitcoin/network/config/address.hpp:39:32: note: candidate constructor not viable: no known conversion from 'endpoint' to 'co>
   39 |     DEFAULT_COPY_MOVE_DESTRUCT(address);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:178:23: note: expanded from macr>
  178 |     DEFAULT_COPY_MOVE(name); \
      |     ~~~~~~~~~~~~~~~~~~^~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:170:18: note: expanded from macr>
  170 |     DEFAULT_COPY(name); \
      |     ~~~~~~~~~~~~~^~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:162:5: note: expanded from macro>
  162 |     name(const name&) = default; \
      |     ^    ~~~~~~~~~~~
./include/bitcoin/network/config/address.hpp:39:32: note: candidate constructor not viable: no known conversion from 'endpoint' to 'ad>
   39 |     DEFAULT_COPY_MOVE_DESTRUCT(address);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:178:23: note: expanded from macr>
  178 |     DEFAULT_COPY_MOVE(name); \
      |     ~~~~~~~~~~~~~~~~~~^~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:171:18: note: expanded from macr>
  171 |     DEFAULT_MOVE(name)
      |     ~~~~~~~~~~~~~^~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:166:5: note: expanded from macro>
  166 |     name(name&&) = default; \
      |     ^    ~~~~~~
src/config/address.cpp:40:10: note: candidate constructor not viable: no known conversion from 'endpoint' to 'const std::string &' (ak>
   40 | address::address(const std::string& host) THROWS
      |          ^       ~~~~~~~~~~~~~~~~~~~~~~~
src/config/address.cpp:46:10: note: candidate constructor not viable: no known conversion from 'endpoint' to 'messages::address_item &>
   46 | address::address(messages::address_item&& item) NOEXCEPT
      |          ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/config/address.cpp:51:10: note: candidate constructor not viable: no known conversion from 'endpoint' to 'const messages::address_>
   51 | address::address(const messages::address_item& item) NOEXCEPT
      |          ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/config/address.cpp:56:10: note: candidate constructor not viable: no known conversion from 'endpoint' to 'const messages::address_>
   56 | address::address(const messages::address_item::cptr& message) NOEXCEPT
      |          ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/config/address.cpp:61:10: note: candidate constructor not viable: no known conversion from 'endpoint' to 'const asio::endpoint &' >
   61 | address::address(const asio::endpoint& uri) NOEXCEPT
      |          ^       ~~~~~~~~~~~~~~~~~~~~~~~~~
./include/bitcoin/network/config/endpoint.hpp:44:5: note: candidate function
   44 |     operator const address() const NOEXCEPT;
      |     ^
./include/bitcoin/network/config/endpoint.hpp:45:5: note: candidate function
   45 |     operator const authority() const NOEXCEPT;
      |     ^
./include/bitcoin/network/config/address.hpp:39:5: note: passing argument to parameter here
   39 |     DEFAULT_COPY_MOVE_DESTRUCT(address);
      |     ^
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:178:5: note: expanded from macro>
  178 |     DEFAULT_COPY_MOVE(name); \
      |     ^
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:171:5: note: expanded from macro>
  171 |     DEFAULT_MOVE(name)
      |     ^
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:166:16: note: expanded from macr>
  166 |     name(name&&) = default; \
      |                ^
1 error generated.
make: *** [Makefile:2373: src/config/libbitcoin_network_la-address.lo] Error 1
make: *** Waiting for unfinished jobs....

.. which seems to be caused by clang being more strict than gcc and not allowing for the implicit conversion of an endpoint to an address. Adding this small patch fixed the issue for me, so I figured I'd upstream it here.

@evoskuil

evoskuil commented Jun 25, 2025

Copy link
Copy Markdown
Member

Thanks. I would guess that was caused by the movement of these config classes to system. But I'm curious why it hasn't been encountered in any of the system, network, or node CI builds.

Comment thread src/config/address.cpp Outdated

address::address(const asio::endpoint& uri) NOEXCEPT
: address(endpoint{ uri })
: address(address{ endpoint{ uri } })

@evoskuil evoskuil Jun 25, 2025

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm having a hard time figuring out why this should make a difference, as there are just two constructions of the same address object, where the outer is a move construction and the inner is a network::config::address construction from a network::config::endpoint object (which is what it was before the change). Am I missing something?

@evoskuil

evoskuil commented Jun 25, 2025

Copy link
Copy Markdown
Member

In the console output the error messages appear to be truncated. This is the attempt (default move) that should be matching, as none are explicit:

src/config/address.cpp:62:13: error: no viable conversion from 'endpoint' to 'address'
   62 |   : address(endpoint{ uri })
      |             ^~~~~~~~~~~~~~~
./include/bitcoin/network/config/address.hpp:39:32: note: candidate constructor not viable: no known conversion from 'endpoint' to 'co>
   39 |     DEFAULT_COPY_MOVE_DESTRUCT(address);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:178:23: note: expanded from macr>
  178 |     DEFAULT_COPY_MOVE(name); \
      |     ~~~~~~~~~~~~~~~~~~^~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:170:18: note: expanded from macr>
  170 |     DEFAULT_COPY(name); \
      |     ~~~~~~~~~~~~~^~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:162:5: note: expanded from macro>
  162 |     name(const name&) = default; \
      |     ^    ~~~~~~~~~~~
./include/bitcoin/network/config/address.hpp:39:32: note: candidate constructor not viable: no known conversion from 'endpoint' to 'ad>
   39 |     DEFAULT_COPY_MOVE_DESTRUCT(address);
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:178:23: note: expanded from macr>
  178 |     DEFAULT_COPY_MOVE(name); \
      |     ~~~~~~~~~~~~~~~~~~^~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:171:18: note: expanded from macr>
  171 |     DEFAULT_MOVE(name)
      |     ~~~~~~~~~~~~~^~~~~
/nix/store/xx1m8jjhgww56nblbb08vm85610x8bph-libbitcoin-system/include/bitcoin/system/preprocessor.hpp:166:5: note: expanded from macro>
  166 |     name(name&&) = default; \

Because network::endpoint is convertible to network::config::address:

operator const address() const NOEXCEPT;`

@evoskuil

evoskuil commented Jun 25, 2025

Copy link
Copy Markdown
Member

Ahh, maybe it's the first const here:

    operator const address() const NOEXCEPT;

This is unnecessarily restrictive and not consistent with our style. The const object cannot be accepted as a move argument (though it should be accepted by the default copy constructor). Normally there would only be a const return for reference cast operator. Since I can't repro could you please try this with this change (and the corresponding change in endpoint.cpp)?

    operator address() const NOEXCEPT;
    operator authority() const NOEXCEPT;

In either case it looks like a compiler issue (and is passing in all CI) but the const should be removed and might resolve it. Note that the compiler does attempt to match the copy constructor:

name(const name&) = default;

which should succeed. But by wrapping the address with a second construction the const is removed and the move constructor should be matched, which is why I suspect this may be sufficient.

Remove const from address, authority return types.
This fixes a compiler error when building with clang.
@josibake

Copy link
Copy Markdown
Contributor Author

Ahh, maybe it's the first const here:

Thanks for digging in. I confirmed this also fixes the compiler error I'm seeing, and it makes sense why the original patch was working, i.e., stripping the const.

In either case it looks like a compiler issue (and is passing in all CI)

I'm not familiar with your CI, but I was able to confirm on my linux machine that this is specific to clang by building with both clang and gcc. The error only happens with clang , and is then resolved with this patch applied.


If interested, this is what I'm using to build / reproduce the error: https://github.com/josibake/nix-libbitcoin

@evoskuil

evoskuil commented Jun 26, 2025

Copy link
Copy Markdown
Member

You can see our CI builds on the GitHub Actions tab for each repo. Matrix includes Ubuntu, Windows, macOS, gcc, clang, msvc, Xcode, make, cmake, msbuild.

Can you post the clang version that failed?

@evoskuil evoskuil merged commit d59a843 into libbitcoin:master Jun 26, 2025
@josibake

Copy link
Copy Markdown
Contributor Author
clang -v
clang version 19.1.7
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /nix/store/v5gysnyx66ap7kzf9mhas1wv5hrh2dmv-clang-19.1.7/bin

This is using the ClangStdenv toolchain from nix. If it's not the version itself, its possible that in their wrapper they are setting some flags that are causing the error. Haven't had a chance to dig further but will revisit at some point if I get a chance.

@evoskuil

Copy link
Copy Markdown
Member

We test at clang16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants