diff --git a/.drone.jsonnet b/.drone.jsonnet new file mode 100644 index 0000000..7795dcd --- /dev/null +++ b/.drone.jsonnet @@ -0,0 +1,449 @@ +# Copyright 2022 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt + +local library = "assert"; + +local triggers = +{ + branch: [ "master", "develop", "feature/*" ] +}; + +local ubsan = { UBSAN: '1', UBSAN_OPTIONS: 'print_stacktrace=1' }; +local asan = { ASAN: '1' }; + +local linux_pipeline(name, image, environment, packages = "", sources = [], arch = "amd64") = +{ + name: name, + kind: "pipeline", + type: "docker", + trigger: triggers, + platform: + { + os: "linux", + arch: arch + }, + steps: + [ + { + name: "everything", + image: image, + environment: environment, + commands: + [ + 'set -e', + 'uname -a', + 'echo $DRONE_STAGE_MACHINE', + ] + + (if sources != [] then [ ('apt-add-repository "' + source + '"') for source in sources ] else []) + + (if packages != "" then [ 'apt-get update', 'apt-get -y install ' + packages ] else []) + + [ + 'export LIBRARY=' + library, + './.drone/drone.sh', + ] + } + ] +}; + +local macos_pipeline(name, environment, xcode_version = "12.2", osx_version = "catalina", arch = "amd64") = +{ + name: name, + kind: "pipeline", + type: "exec", + trigger: triggers, + platform: { + "os": "darwin", + "arch": arch + }, + node: { + "os": osx_version + }, + steps: [ + { + name: "everything", + environment: environment + { "DEVELOPER_DIR": "/Applications/Xcode-" + xcode_version + ".app/Contents/Developer" }, + commands: + [ + 'export LIBRARY=' + library, + './.drone/drone.sh', + ] + } + ] +}; + +local windows_pipeline(name, image, environment, arch = "amd64") = +{ + name: name, + kind: "pipeline", + type: "docker", + trigger: triggers, + platform: + { + os: "windows", + arch: arch + }, + "steps": + [ + { + name: "everything", + image: image, + environment: environment, + commands: + [ + 'cmd /C .drone\\\\drone.bat ' + library, + ] + } + ] +}; + +[ + linux_pipeline( + "Linux 16.04 GCC 4.4", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'gcc', COMPILER: 'g++-4.4', CXXSTD: '98,0x' }, + "g++-4.4", + [ "ppa:ubuntu-toolchain-r/test" ], + ), + + linux_pipeline( + "Linux 16.04 GCC 4.6", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'gcc', COMPILER: 'g++-4.6', CXXSTD: '98,0x' }, + "g++-4.6", + [ "ppa:ubuntu-toolchain-r/test" ], + ), + + linux_pipeline( + "Linux 16.04 GCC 4.7", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'gcc', COMPILER: 'g++-4.7', CXXSTD: '98,0x' }, + "g++-4.7", + ), + + linux_pipeline( + "Linux 16.04 GCC 4.8", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '03,11' }, + "g++-4.8", + ), + + linux_pipeline( + "Linux 16.04 GCC 4.9", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '03,11' }, + "g++-4.9", + ), + + linux_pipeline( + "Linux 16.04 GCC 5* 32/64", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14', ADDRMD: '32,64' }, + ), + + linux_pipeline( + "Linux 18.04 GCC 6", + "cppalliance/droneubuntu1804:1", + { TOOLSET: 'gcc', COMPILER: 'g++-6', CXXSTD: '03,11,14' }, + "g++-6", + ), + + linux_pipeline( + "Linux 18.04 GCC 7* 32/64", + "cppalliance/droneubuntu1804:1", + { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17', ADDRMD: '32,64' }, + ), + + linux_pipeline( + "Linux 18.04 GCC 8", + "cppalliance/droneubuntu1804:1", + { TOOLSET: 'gcc', COMPILER: 'g++-8', CXXSTD: '03,11,14,17' }, + "g++-8", + ), + + linux_pipeline( + "Linux 20.04 GCC 9* 32/64", + "cppalliance/droneubuntu2004:1", + { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' }, + ), + + linux_pipeline( + "Linux 20.04 GCC 9* ARM64", + "cppalliance/droneubuntu2004:multiarch", + { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' }, + arch="arm64", + ), + + linux_pipeline( + "Linux 20.04 GCC 9* S390x", + "cppalliance/droneubuntu2004:multiarch", + { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' }, + arch="s390x", + ), + + linux_pipeline( + "Linux 20.04 GCC 10", + "cppalliance/droneubuntu2004:1", + { TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20' }, + "g++-10", + ), + + linux_pipeline( + "Linux 22.04 GCC 11* 32/64", + "cppalliance/droneubuntu2204:1", + { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' }, + ), + + linux_pipeline( + "Linux 22.04 GCC 12 32/64", + "cppalliance/droneubuntu2204:1", + { TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' }, + "g++-12-multilib", + ), + + linux_pipeline( + "Linux 24.04 GCC 13* 32/64", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' }, + ), + + linux_pipeline( + "Linux 24.04 GCC 14 32/64 ASAN", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' } + asan, + "g++-14-multilib", + ), + + linux_pipeline( + "Linux 24.04 GCC 14 32/64 UBSAN", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' } + ubsan, + "g++-14-multilib", + ), + + linux_pipeline( + "Linux 25.10 GCC 15 32/64", + "cppalliance/droneubuntu2510:1", + { TOOLSET: 'gcc', COMPILER: 'g++-15', CXXSTD: '11,14,17,20,23,2c', ADDRMD: '32,64' }, + "g++-15-multilib", + ), + + linux_pipeline( + "Linux 16.04 Clang 3.5", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '03,11,14' }, + "clang-3.5", + ), + + linux_pipeline( + "Linux 16.04 Clang 3.6", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '03,11,14' }, + "clang-3.6", + ), + + linux_pipeline( + "Linux 16.04 Clang 3.7", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '03,11,14' }, + "clang-3.7", + ), + + linux_pipeline( + "Linux 16.04 Clang 3.8", + "cppalliance/droneubuntu1604:1", + { TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '03,11,14' }, + "clang-3.8", + ), + + linux_pipeline( + "Linux 18.04 Clang 3.9", + "cppalliance/droneubuntu1804:1", + { TOOLSET: 'clang', COMPILER: 'clang++-3.9', CXXSTD: '03,11,14' }, + "clang-3.9", + ), + + linux_pipeline( + "Linux 18.04 Clang 4.0", + "cppalliance/droneubuntu1804:1", + { TOOLSET: 'clang', COMPILER: 'clang++-4.0', CXXSTD: '03,11,14' }, + "clang-4.0", + ), + + linux_pipeline( + "Linux 18.04 Clang 5.0", + "cppalliance/droneubuntu1804:1", + { TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '03,11,14,1z' }, + "clang-5.0", + ), + + linux_pipeline( + "Linux 18.04 Clang 6.0", + "cppalliance/droneubuntu1804:1", + { TOOLSET: 'clang', COMPILER: 'clang++-6.0', CXXSTD: '03,11,14,17' }, + "clang-6.0", + ), + + linux_pipeline( + "Linux 20.04 Clang 7", + "cppalliance/droneubuntu2004:1", + { TOOLSET: 'clang', COMPILER: 'clang++-7', CXXSTD: '03,11,14,17' }, + "clang-7", + ), + + linux_pipeline( + "Linux 20.04 Clang 8", + "cppalliance/droneubuntu2004:1", + { TOOLSET: 'clang', COMPILER: 'clang++-8', CXXSTD: '03,11,14,17' }, + "clang-8", + ), + + linux_pipeline( + "Linux 20.04 Clang 9", + "cppalliance/droneubuntu2004:1", + { TOOLSET: 'clang', COMPILER: 'clang++-9', CXXSTD: '03,11,14,17,2a' }, + "clang-9", + ), + + linux_pipeline( + "Linux 20.04 Clang 10", + "cppalliance/droneubuntu2004:1", + { TOOLSET: 'clang', COMPILER: 'clang++-10', CXXSTD: '03,11,14,17,2a' }, + "clang-10", + ), + + linux_pipeline( + "Linux 20.04 Clang 11", + "cppalliance/droneubuntu2004:1", + { TOOLSET: 'clang', COMPILER: 'clang++-11', CXXSTD: '03,11,14,17,2a' }, + "clang-11", + ), + + linux_pipeline( + "Linux 20.04 Clang 12", + "cppalliance/droneubuntu2004:1", + { TOOLSET: 'clang', COMPILER: 'clang++-12', CXXSTD: '03,11,14,17,2a' }, + "clang-12", + ), + + linux_pipeline( + "Linux 22.04 Clang 13", + "cppalliance/droneubuntu2204:1", + { TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '03,11,14,17,20' }, + "clang-13", + ), + + linux_pipeline( + "Linux 22.04 Clang 14", + "cppalliance/droneubuntu2204:1", + { TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' }, + "clang-14", + ), + + linux_pipeline( + "Linux 22.04 Clang 15", + "cppalliance/droneubuntu2204:1", + { TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' }, + "clang-15", + ), + + linux_pipeline( + "Linux 24.04 Clang 16", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '03,11,14,17,20,2b' }, + "clang-16", + ), + + linux_pipeline( + "Linux 24.04 Clang 17", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '03,11,14,17,20,2b' }, + "clang-17", + ), + + linux_pipeline( + "Linux 24.04 Clang 18", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '03,11,14,17,20,2b' }, + "clang-18", + ), + + linux_pipeline( + "Linux 24.04 Clang 19", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '03,11,14,17,20,2b' }, + "clang-18", + ), + + linux_pipeline( + "Linux 24.04 Clang 20 UBSAN", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '03,11,14,17,20,2b' } + ubsan, + "clang-20", + ), + + linux_pipeline( + "Linux 24.04 Clang 20 ASAN", + "cppalliance/droneubuntu2404:1", + { TOOLSET: 'clang', COMPILER: 'clang++-20', CXXSTD: '03,11,14,17,20,2b' } + asan, + "clang-20", + ), + + linux_pipeline( + "Linux 25.10 Clang 21", + "cppalliance/droneubuntu2510:1", + { TOOLSET: 'clang', COMPILER: 'clang++-21', CXXSTD: '03,11,14,17,20,23,2c' }, + "clang-21", + ), + + macos_pipeline( + "MacOS 10.15 Xcode 12.2 UBSAN", + { TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + ubsan, + ), + + macos_pipeline( + "MacOS 10.15 Xcode 12.2 ASAN", + { TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + asan, + ), + + macos_pipeline( + "MacOS 12.4 Xcode 13.4.1 UBSAN", + { TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,20,2b' } + ubsan, + xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64", + ), + + macos_pipeline( + "MacOS 12.4 Xcode 13.4.1 ASAN", + { TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,20,2b' } + asan, + xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64", + ), + + windows_pipeline( + "Windows VS2015 msvc-14.0", + "cppalliance/dronevs2015", + { TOOLSET: 'msvc-14.0', CXXSTD: '14,latest', B2_DONT_EMBED_MANIFEST: '1' }, + ), + + windows_pipeline( + "Windows VS2017 msvc-14.1", + "cppalliance/dronevs2017", + { TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' }, + ), + + windows_pipeline( + "Windows VS2019 msvc-14.2", + "cppalliance/dronevs2019", + { TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' }, + ), + + windows_pipeline( + "Windows VS2022 msvc-14.3", + "cppalliance/dronevs2022:1", + { TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' }, + ), + + windows_pipeline( + "Windows VS2026 msvc-14.5", + "cppalliance/dronevs2026:1", + { TOOLSET: 'msvc-14.5', CXXSTD: '14,17,20,latest' }, + ), +] diff --git a/.drone/drone.bat b/.drone/drone.bat new file mode 100644 index 0000000..66aaf78 --- /dev/null +++ b/.drone/drone.bat @@ -0,0 +1,23 @@ +@REM Copyright 2022 Peter Dimov +@REM Distributed under the Boost Software License, Version 1.0. +@REM https://www.boost.org/LICENSE_1_0.txt + +@ECHO ON + +set LIBRARY=%1 +set DRONE_BUILD_DIR=%CD% + +set BOOST_BRANCH=develop +if "%DRONE_BRANCH%" == "master" set BOOST_BRANCH=master +cd .. +git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root +cd boost-root +git submodule update --init tools/boostdep +xcopy /s /e /q %DRONE_BUILD_DIR% libs\%LIBRARY%\ +python tools/boostdep/depinst/depinst.py %LIBRARY% +cmd /c bootstrap +b2 -d0 headers + +if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD% +if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD% +b2 -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker diff --git a/.drone/drone.sh b/.drone/drone.sh new file mode 100755 index 0000000..2f2125d --- /dev/null +++ b/.drone/drone.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# Copyright 2022 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt + +set -ex +export PATH=~/.local/bin:/usr/local/bin:$PATH + +DRONE_BUILD_DIR=$(pwd) + +BOOST_BRANCH=develop +if [ "$DRONE_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi + +cd .. +git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root +cd boost-root +git submodule update --init tools/boostdep +cp -r $DRONE_BUILD_DIR/* libs/$LIBRARY +python tools/boostdep/depinst/depinst.py $LIBRARY +./bootstrap.sh +./b2 -d0 headers + +echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam +./b2 -j3 libs/$LIBRARY/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release ${ADDRMD:+address-model=$ADDRMD} ${UBSAN:+undefined-sanitizer=norecover debug-symbols=on} ${ASAN:+address-sanitizer=norecover debug-symbols=on} ${LINKFLAGS:+linkflags=$LINKFLAGS} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0ea2fde..1294803 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,105 +17,220 @@ jobs: fail-fast: false matrix: include: - - toolset: gcc-4.7 - cxxstd: "03,11" - os: ubuntu-16.04 - install: g++-4.7 - toolset: gcc-4.8 cxxstd: "03,11" - os: ubuntu-16.04 + container: ubuntu:18.04 + os: ubuntu-latest install: g++-4.8 - - toolset: gcc-4.9 - cxxstd: "03,11" - os: ubuntu-16.04 - install: g++-4.9 - toolset: gcc-5 cxxstd: "03,11,14,1z" - os: ubuntu-16.04 + container: ubuntu:18.04 + os: ubuntu-latest + install: g++-5 - toolset: gcc-6 cxxstd: "03,11,14,1z" - os: ubuntu-16.04 + container: ubuntu:18.04 + os: ubuntu-latest install: g++-6 - toolset: gcc-7 cxxstd: "03,11,14,17" - os: ubuntu-18.04 + container: ubuntu:20.04 + os: ubuntu-latest + install: g++-7 - toolset: gcc-8 cxxstd: "03,11,14,17,2a" - os: ubuntu-18.04 + container: ubuntu:20.04 + os: ubuntu-latest + install: g++-8 - toolset: gcc-9 cxxstd: "03,11,14,17,2a" - os: ubuntu-18.04 + container: ubuntu:20.04 + os: ubuntu-latest - toolset: gcc-10 cxxstd: "03,11,14,17,2a" - os: ubuntu-18.04 - - toolset: clang - compiler: clang++-3.5 - cxxstd: "03,11,14" - os: ubuntu-16.04 - install: clang-3.5 - - toolset: clang - compiler: clang++-3.6 - cxxstd: "03,11,14" - os: ubuntu-16.04 - install: clang-3.6 - - toolset: clang - compiler: clang++-3.7 - cxxstd: "03,11,14" - os: ubuntu-16.04 - install: clang-3.7 - - toolset: clang - compiler: clang++-3.8 - cxxstd: "03,11,14" - os: ubuntu-16.04 - install: clang-3.8 + container: ubuntu:20.04 + os: ubuntu-latest + install: g++-10 + - toolset: gcc-11 + cxxstd: "03,11,14,17,2a" + os: ubuntu-22.04 + install: g++-11 + - toolset: gcc-12 + cxxstd: "03,11,14,17,20,2b" + os: ubuntu-22.04 + install: g++-12 + - toolset: gcc-13 + cxxstd: "03,11,14,17,20,2b" + os: ubuntu-latest + container: ubuntu:24.04 + install: g++-13 + - toolset: gcc-14 + cxxstd: "03,11,14,17,20,2b" + os: ubuntu-latest + container: ubuntu:24.04 + install: g++-14 + - toolset: gcc-15 + cxxstd: "03,11,14,17,20,23,2c" + os: ubuntu-latest + container: ubuntu:25.10 + install: g++-15 - toolset: clang compiler: clang++-3.9 cxxstd: "03,11,14" - os: ubuntu-16.04 + container: ubuntu:18.04 + os: ubuntu-latest install: clang-3.9 - toolset: clang compiler: clang++-4.0 cxxstd: "03,11,14" - os: ubuntu-16.04 + container: ubuntu:18.04 + os: ubuntu-latest install: clang-4.0 - toolset: clang compiler: clang++-5.0 cxxstd: "03,11,14,1z" - os: ubuntu-16.04 + container: ubuntu:18.04 + os: ubuntu-latest install: clang-5.0 - toolset: clang compiler: clang++-6.0 cxxstd: "03,11,14,17" - os: ubuntu-18.04 + container: ubuntu:20.04 + os: ubuntu-latest + install: clang-6.0 - toolset: clang compiler: clang++-7 cxxstd: "03,11,14,17" - os: ubuntu-18.04 + container: ubuntu:20.04 + os: ubuntu-latest install: clang-7 - toolset: clang compiler: clang++-8 cxxstd: "03,11,14,17,2a" - os: ubuntu-20.04 + container: ubuntu:20.04 + os: ubuntu-latest + install: clang-8 - toolset: clang compiler: clang++-9 cxxstd: "03,11,14,17,2a" - os: ubuntu-20.04 + container: ubuntu:20.04 + os: ubuntu-latest + install: clang-9 - toolset: clang compiler: clang++-10 cxxstd: "03,11,14,17,2a" - os: ubuntu-20.04 + container: ubuntu:20.04 + os: ubuntu-latest + install: clang-10 + - toolset: clang + compiler: clang++-11 + cxxstd: "03,11,14,17,2a" + container: ubuntu:20.04 + os: ubuntu-latest + install: clang-11 - toolset: clang + compiler: clang++-12 cxxstd: "03,11,14,17,2a" - os: macos-10.15 + container: ubuntu:20.04 + os: ubuntu-latest + install: clang-12 + - toolset: clang + compiler: clang++-13 + cxxstd: "03,11,14,17,20,2b" + container: ubuntu:22.04 + os: ubuntu-latest + install: clang-13 + - toolset: clang + compiler: clang++-14 + cxxstd: "03,11,14,17,20,2b" + container: ubuntu:22.04 + os: ubuntu-latest + install: clang-14 + - toolset: clang + compiler: clang++-15 + cxxstd: "03,11,14,17,20,2b" + container: ubuntu:22.04 + os: ubuntu-latest + install: clang-15 + - toolset: clang + compiler: clang++-16 + cxxstd: "03,11,14,17,20,2b" + container: ubuntu:24.04 + os: ubuntu-latest + install: clang-16 + - toolset: clang + compiler: clang++-17 + cxxstd: "03,11,14,17,20,2b" + container: ubuntu:24.04 + os: ubuntu-latest + install: clang-17 + - toolset: clang + compiler: clang++-18 + cxxstd: "03,11,14,17,20,2b" + container: ubuntu:24.04 + os: ubuntu-latest + install: clang-18 + - toolset: clang + compiler: clang++-19 + cxxstd: "03,11,14,17,20,2b" + container: ubuntu:24.04 + os: ubuntu-latest + install: clang-19 + - toolset: clang + compiler: clang++-20 + cxxstd: "03,11,14,17,20,23,2c" + container: ubuntu:24.04 + os: ubuntu-latest + install: clang-20 + - toolset: clang + compiler: clang++-21 + cxxstd: "03,11,14,17,20,23,2c" + container: ubuntu:25.10 + os: ubuntu-latest + install: clang-21 + - toolset: clang + cxxstd: "03,11,14,17,20,2b" + os: macos-14 + - toolset: clang + cxxstd: "03,11,14,17,20,2b" + os: macos-15 + - toolset: clang + cxxstd: "03,11,14,17,20,23,2c" + os: macos-26 runs-on: ${{matrix.os}} + container: + image: ${{matrix.container}} + volumes: + - /node20217:/node20217:rw,rshared + - ${{ startsWith(matrix.container, 'ubuntu:1') && '/node20217:/__e/node20:ro,rshared' || ' ' }} + + defaults: + run: + shell: bash + steps: - - uses: actions/checkout@v2 + - name: Setup container environment + if: matrix.container + run: | + apt-get update + apt-get -y install sudo python3 git g++ curl xz-utils + + - name: Install nodejs20glibc2.17 + if: ${{ startsWith( matrix.container, 'ubuntu:1' ) }} + run: | + curl -LO https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz + tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217 + ldd /__e/node20/bin/node + + - uses: actions/checkout@v4 - name: Install packages if: matrix.install - run: sudo apt install ${{matrix.install}} + run: | + sudo apt-get update + sudo apt-get -y install ${{matrix.install}} - name: Setup Boost run: | @@ -135,7 +250,7 @@ jobs: cd boost-root cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY git submodule update --init tools/boostdep - python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY + python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY ./bootstrap.sh ./b2 -d0 headers @@ -154,23 +269,23 @@ jobs: fail-fast: false matrix: include: - - toolset: msvc-14.1 - cxxstd: "14,17,latest" + - toolset: msvc-14.3 + cxxstd: "14,17,20,latest" addrmd: 32,64 - os: windows-2016 - - toolset: msvc-14.2 - cxxstd: "14,17,latest" + os: windows-2022 + - toolset: clang-win + cxxstd: "14,17,20,latest" addrmd: 32,64 - os: windows-2019 + os: windows-2025 - toolset: gcc cxxstd: "03,11,14,17,2a" addrmd: 64 - os: windows-2019 + os: windows-2022 runs-on: ${{matrix.os}} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup Boost shell: cmd @@ -198,4 +313,334 @@ jobs: shell: cmd run: | cd ../boost-root - b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release + b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker + + posix-cmake-subdir: + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + - os: macos-latest + + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + if: matrix.install + run: sudo apt-get -y install ${{matrix.install}} + + - name: Setup Boost + run: | + echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY + LIBRARY=${GITHUB_REPOSITORY#*/} + echo LIBRARY: $LIBRARY + echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV + echo GITHUB_BASE_REF: $GITHUB_BASE_REF + echo GITHUB_REF: $GITHUB_REF + REF=${GITHUB_BASE_REF:-$GITHUB_REF} + REF=${REF#refs/heads/} + echo REF: $REF + BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true + echo BOOST_BRANCH: $BOOST_BRANCH + cd .. + git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root + cd boost-root + cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY + git submodule update --init tools/boostdep + python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY + + - name: Use library with add_subdirectory + run: | + cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test + mkdir __build__ && cd __build__ + cmake .. + cmake --build . + ctest --output-on-failure --no-tests=error + + posix-cmake-install: + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + - os: macos-latest + + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + if: matrix.install + run: sudo apt-get -y install ${{matrix.install}} + + - name: Setup Boost + run: | + echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY + LIBRARY=${GITHUB_REPOSITORY#*/} + echo LIBRARY: $LIBRARY + echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV + echo GITHUB_BASE_REF: $GITHUB_BASE_REF + echo GITHUB_REF: $GITHUB_REF + REF=${GITHUB_BASE_REF:-$GITHUB_REF} + REF=${REF#refs/heads/} + echo REF: $REF + BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true + echo BOOST_BRANCH: $BOOST_BRANCH + cd .. + git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root + cd boost-root + cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY + git submodule update --init tools/boostdep + python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY + + - name: Configure + run: | + cd ../boost-root + mkdir __build__ && cd __build__ + cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local .. + + - name: Install + run: | + cd ../boost-root/__build__ + cmake --build . --target install + + - name: Use the installed library + run: | + cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__ + cmake -DCMAKE_INSTALL_PREFIX=~/.local .. + cmake --build . + ctest --output-on-failure --no-tests=error + + posix-cmake-test: + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + - os: macos-latest + + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v4 + + - name: Install packages + if: matrix.install + run: sudo apt-get -y install ${{matrix.install}} + + - name: Setup Boost + run: | + echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY + LIBRARY=${GITHUB_REPOSITORY#*/} + echo LIBRARY: $LIBRARY + echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV + echo GITHUB_BASE_REF: $GITHUB_BASE_REF + echo GITHUB_REF: $GITHUB_REF + REF=${GITHUB_BASE_REF:-$GITHUB_REF} + REF=${REF#refs/heads/} + echo REF: $REF + BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true + echo BOOST_BRANCH: $BOOST_BRANCH + cd .. + git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root + cd boost-root + cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY + git submodule update --init tools/boostdep + python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY + + - name: Configure + run: | + cd ../boost-root + mkdir __build__ && cd __build__ + cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON .. + + - name: Build tests + run: | + cd ../boost-root/__build__ + cmake --build . --target tests + + - name: Run tests + run: | + cd ../boost-root/__build__ + ctest --output-on-failure --no-tests=error + + windows-cmake-subdir: + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v4 + + - name: Setup Boost + shell: cmd + run: | + echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% + for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi + echo LIBRARY: %LIBRARY% + echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% + echo GITHUB_BASE_REF: %GITHUB_BASE_REF% + echo GITHUB_REF: %GITHUB_REF% + if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% + set BOOST_BRANCH=develop + for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master + echo BOOST_BRANCH: %BOOST_BRANCH% + cd .. + git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root + cd boost-root + xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ + git submodule update --init tools/boostdep + python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% + + - name: Use library with add_subdirectory (Debug) + shell: cmd + run: | + cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test + mkdir __build__ && cd __build__ + cmake .. + cmake --build . --config Debug + ctest --output-on-failure --no-tests=error -C Debug + + - name: Use library with add_subdirectory (Release) + shell: cmd + run: | + cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test/__build__ + cmake --build . --config Release + ctest --output-on-failure --no-tests=error -C Release + + windows-cmake-install: + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v4 + + - name: Setup Boost + shell: cmd + run: | + echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% + for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi + echo LIBRARY: %LIBRARY% + echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% + echo GITHUB_BASE_REF: %GITHUB_BASE_REF% + echo GITHUB_REF: %GITHUB_REF% + if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% + set BOOST_BRANCH=develop + for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master + echo BOOST_BRANCH: %BOOST_BRANCH% + cd .. + git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root + cd boost-root + xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ + git submodule update --init tools/boostdep + python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% + + - name: Configure + shell: cmd + run: | + cd ../boost-root + mkdir __build__ && cd __build__ + cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. + + - name: Install (Debug) + shell: cmd + run: | + cd ../boost-root/__build__ + cmake --build . --target install --config Debug + + - name: Install (Release) + shell: cmd + run: | + cd ../boost-root/__build__ + cmake --build . --target install --config Release + + - name: Use the installed library (Debug) + shell: cmd + run: | + cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__ + cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. + cmake --build . --config Debug + ctest --output-on-failure --no-tests=error -C Debug + + - name: Use the installed library (Release) + shell: cmd + run: | + cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test/__build__ + cmake --build . --config Release + ctest --output-on-failure --no-tests=error -C Release + + windows-cmake-test: + strategy: + fail-fast: false + matrix: + include: + - os: windows-latest + + runs-on: ${{matrix.os}} + + steps: + - uses: actions/checkout@v4 + + - name: Setup Boost + shell: cmd + run: | + echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% + for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi + echo LIBRARY: %LIBRARY% + echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% + echo GITHUB_BASE_REF: %GITHUB_BASE_REF% + echo GITHUB_REF: %GITHUB_REF% + if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% + set BOOST_BRANCH=develop + for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master + echo BOOST_BRANCH: %BOOST_BRANCH% + cd .. + git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root + cd boost-root + xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ + git submodule update --init tools/boostdep + python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% + + - name: Configure + shell: cmd + run: | + cd ../boost-root + mkdir __build__ && cd __build__ + cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON .. + + - name: Build tests (Debug) + shell: cmd + run: | + cd ../boost-root/__build__ + cmake --build . --target tests --config Debug + + - name: Run tests (Debug) + shell: cmd + run: | + cd ../boost-root/__build__ + ctest --output-on-failure --no-tests=error -C Debug + + - name: Build tests (Release) + shell: cmd + run: | + cd ../boost-root/__build__ + cmake --build . --target tests --config Release + + - name: Run tests (Release) + shell: cmd + run: | + cd ../boost-root/__build__ + ctest --output-on-failure --no-tests=error -C Release diff --git a/.travis.yml b/.travis.yml index ced831b..94f0f74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -324,8 +324,9 @@ matrix: env: CMAKE=1 script: - mkdir __build__ && cd __build__ - - cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=assert .. - - ctest --output-on-failure -R boost_assert + - cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=assert .. + - cmake --build . --target tests + - ctest --output-on-failure - os: linux env: CMAKE_SUBDIR=1 @@ -341,8 +342,9 @@ matrix: - os: linux env: CMAKE_INSTALL=1 script: + - pip install --user cmake - mkdir __build__ && cd __build__ - - cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=assert -DCMAKE_INSTALL_PREFIX=~/.local .. + - cmake -DBOOST_INCLUDE_LIBRARIES=assert -DCMAKE_INSTALL_PREFIX=~/.local .. - cmake --build . --target install - cd ../libs/assert/test/cmake_install_test && mkdir __build__ && cd __build__ - cmake -DCMAKE_INSTALL_PREFIX=~/.local .. diff --git a/CMakeLists.txt b/CMakeLists.txt index 0066aeb..5b33422 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ -# Copyright 2018, 2019 Peter Dimov +# Copyright 2018-2025 Peter Dimov # Distributed under the Boost Software License, Version 1.0. -# See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt +# https://www.boost.org/LICENSE_1_0.txt -# We support CMake 3.5, but prefer 3.16 policies and behavior -cmake_minimum_required(VERSION 3.5...3.16) +# We support CMake 3.5, but prefer 3.31 policies and behavior +cmake_minimum_required(VERSION 3.5...3.31) project(boost_assert VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) @@ -17,13 +17,28 @@ target_link_libraries(boost_assert Boost::config ) -# boost_install requires PROJECT_VERSION -# Without the superproject, we don't have any, so skip installation +# Add headers and .natvis to project, for better IDE integration -if(BOOST_SUPERPROJECT_VERSION) +if(NOT CMAKE_VERSION VERSION_LESS 3.19) - include(BoostInstall) - boost_install(TARGETS boost_assert HEADER_DIRECTORY include/) + # Using target_sources with PRIVATE or PUBLIC on INTERFACE targets requires 3.19 + + file(GLOB_RECURSE headers CONFIGURE_DEPENDS include/*.hpp) + target_sources(boost_assert PRIVATE ${headers}) + unset(headers) + + if(MSVC) + + # Only Visual Studio needs this, but the generator may also be Ninja + target_sources(boost_assert PUBLIC extra/boost_assert.natvis) + + endif() + + # Make IDE project folders match directory structure + + get_target_property(sources boost_assert SOURCES) + source_group(TREE ${PROJECT_SOURCE_DIR} FILES ${sources}) + unset(sources) endif() diff --git a/appveyor.yml b/appveyor.yml index 7203084..ed79645 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,17 +14,40 @@ branches: environment: matrix: - - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0 ADDRMD: 32 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 TOOLSET: msvc-12.0,msvc-14.0 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 TOOLSET: msvc-14.1,clang-win - CXXSTD: 14,17 + CXXSTD: 14,17,latest + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + TOOLSET: msvc-14.0 + __CXXFLAGS__: /ZI /FS + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + TOOLSET: msvc-14.1 + CXXSTD: 14,17,latest + __CXXFLAGS__: /ZI /FS - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 TOOLSET: msvc-14.2 - CXXSTD: 14,17 + CXXSTD: 14,17,20,latest + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + ADDPATH: C:\cygwin\bin; + TOOLSET: gcc + CXXSTD: 03,11,14,1z + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + ADDPATH: C:\cygwin64\bin; + TOOLSET: gcc + CXXSTD: 03,11,14,1z + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + ADDPATH: C:\mingw\bin; + TOOLSET: gcc + CXXSTD: 03,11,14,1z + - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin; + TOOLSET: gcc + CXXSTD: 03,11,14,1z - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 CMAKE: 1 - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 @@ -44,10 +67,11 @@ install: - cd boost-root - git submodule update --init tools/build - git submodule update --init tools/boost_install + - git submodule update --init tools/cmake + - git submodule update --init libs/headers - git submodule update --init libs/config - git submodule update --init libs/core - - git submodule update --init libs/headers - - git submodule update --init tools/cmake + - git submodule update --init libs/throw_exception - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\assert\ - cmd /c bootstrap - b2 -d0 headers @@ -56,16 +80,18 @@ build: off test_script: + - PATH=%ADDPATH%%PATH% - if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD% - if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD% - - if "%CMAKE%%CMAKE_SUBDIR%%CMAKE_INSTALL%" == "" b2 -j 3 libs/assert/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% + - if not "%__CXXFLAGS__%" == "" set __CXXFLAGS__=cxxflags="%__CXXFLAGS__%" + - if "%CMAKE%%CMAKE_SUBDIR%%CMAKE_INSTALL%" == "" b2 -j 1 libs/assert/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% %__CXXFLAGS__% variant=debug,release - if not "%CMAKE%" == "" mkdir __build__ && cd __build__ - - if not "%CMAKE%" == "" cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES=assert .. - - if not "%CMAKE%" == "" ctest --output-on-failure -R boost_assert -C Debug - - if not "%CMAKE%" == "" ctest --output-on-failure -R boost_assert -C Release - - if not "%CMAKE%" == "" ctest --output-on-failure -R boost_assert -C MinSizeRel - - if not "%CMAKE%" == "" ctest --output-on-failure -R boost_assert -C RelWithDebInfo + - if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=assert .. + - if not "%CMAKE%" == "" cmake --build . --target tests --config Debug & ctest --output-on-failure --no-tests=error -C Debug + - if not "%CMAKE%" == "" cmake --build . --target tests --config Release & ctest --output-on-failure --no-tests=error -C Release + - if not "%CMAKE%" == "" cmake --build . --target tests --config MinSizeRel & ctest --output-on-failure --no-tests=error -C MinSizeRel + - if not "%CMAKE%" == "" cmake --build . --target tests --config RelWithDebInfo & ctest --output-on-failure --no-tests=error -C RelWithDebInfo - if not "%CMAKE_SUBDIR%" == "" cd libs/assert/test/cmake_subdir_test && mkdir __build__ && cd __build__ - if not "%CMAKE_SUBDIR%" == "" cmake .. @@ -75,7 +101,7 @@ test_script: - if not "%CMAKE_SUBDIR%" == "" cmake --build . --config RelWithDebInfo && cmake --build . --target check --config RelWithDebInfo - if not "%CMAKE_INSTALL%" == "" mkdir __build__ && cd __build__ - - if not "%CMAKE_INSTALL%" == "" cmake -DBOOST_ENABLE_CMAKE=1 -DBoost_VERBOSE=1 -DBOOST_INCLUDE_LIBRARIES="assert;config" -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. + - if not "%CMAKE_INSTALL%" == "" cmake -DBOOST_INCLUDE_LIBRARIES=assert -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. - if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Debug - if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Release - if not "%CMAKE_INSTALL%" == "" cd ../libs/assert/test/cmake_install_test && mkdir __build__ && cd __build__ diff --git a/build.jam b/build.jam new file mode 100644 index 0000000..c2bd74a --- /dev/null +++ b/build.jam @@ -0,0 +1,20 @@ +# Copyright 2023-2024 René Ferdinand Rivera Morell +# Copyright 2024 Peter Dimov +# Distributed under the Boost Software License, Version 1.0. +# https://www.boost.org/LICENSE_1_0.txt + +require-b2 5.2 ; + +constant boost_dependencies : + /boost/config//boost_config + ; + +project /boost/assert ; + +explicit + [ alias boost_assert : : : : include $(boost_dependencies) ] + [ alias all : boost_assert test ] + ; + +call-if : boost-library assert + ; diff --git a/doc/Jamfile b/doc/Jamfile index 5943a2a..539ce26 100644 --- a/doc/Jamfile +++ b/doc/Jamfile @@ -5,13 +5,9 @@ # http://www.boost.org/LICENSE_1_0.txt) import asciidoctor ; -# import boostbook ; html assert.html : index.adoc ; -# docbook assert.docbook : index.adoc ; -# boostbook assert.html : assert.docbook : onehtml ; - install html_ : assert.html : html ; pdf assert.pdf : index.adoc ; diff --git a/doc/assert.adoc b/doc/assert.adoc index 3926224..e050488 100644 --- a/doc/assert.adoc +++ b/doc/assert.adoc @@ -32,7 +32,7 @@ code. * If the macro `BOOST_ENABLE_ASSERT_HANDLER` is defined when `` is included, `BOOST_ASSERT(expr)` expands to + -``` +```none (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) ``` @@ -46,6 +46,9 @@ This is true regardless of whether `NDEBUG` is defined. ``` namespace boost { +#if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) + BOOST_NORETURN +#endif void assertion_failed(char const * expr, char const * function, char const * file, long line); } @@ -75,7 +78,7 @@ the macro `NDEBUG` is defined. * If the macro `BOOST_ENABLE_ASSERT_HANDLER` is defined when `` is included, `BOOST_ASSERT_MSG(expr,msg)` expands to + -``` +```none (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) ``` @@ -87,6 +90,9 @@ This is true regardless of whether `NDEBUG` is defined. ``` namespace boost { +#if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) + BOOST_NORETURN +#endif void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line); } diff --git a/doc/changes.adoc b/doc/changes.adoc index 303c291..b7d6f5b 100644 --- a/doc/changes.adoc +++ b/doc/changes.adoc @@ -1,5 +1,5 @@ //// -Copyright 2019 Peter Dimov +Copyright 2019, 2021 Peter Dimov Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt //// @@ -10,6 +10,24 @@ http://www.boost.org/LICENSE_1_0.txt :toc-title: :idprefix: +## Changes in 1.88.0 + +* When `BOOST_ASSERT_HANDLER_IS_NORETURN` is defined, `boost::assertion_failed` + and `boost::assertion_failed_msg` are declared as `BOOST_NORETURN`. + +## Changes in 1.79.0 + +* `source_location().file_name()` and `source_location().function_name()` + now return `""` instead of `"(unknown)"`. +* Added a `source_location` constructor from `std::source_location`. +* Changed `BOOST_CURRENT_LOCATION` to more closely match the behavior of + `std::source_location::current()`, such as being usable at top level or + as a default function argument. + +## Changes in 1.78.0 + +* Added `source_location::to_string`. + ## Changes in 1.73.0 * Added `source_location`. diff --git a/doc/current_function.adoc b/doc/current_function.adoc index 21453a2..b65f6d6 100644 --- a/doc/current_function.adoc +++ b/doc/current_function.adoc @@ -18,9 +18,10 @@ http://www.boost.org/LICENSE_1_0.txt The header `` defines a single macro, `BOOST_CURRENT_FUNCTION`, similar to the C99 predefined identifier `\\__func__`. -`BOOST_CURRENT_FUNCTION` expands to a string literal containing -the (fully qualified, if possible) name of the enclosing function. If there is -no enclosing function, the behavior is unspecified. +`BOOST_CURRENT_FUNCTION` expands to either a string literal, or the name of a +character array local to the current function, containing the (fully qualified, +if possible) name of the enclosing function. If there is no enclosing function, +the behavior varies by compiler, but is usually a compile error. Some compilers do not provide a way to obtain the name of the current enclosing function. On such compilers, or when the macro `BOOST_DISABLE_CURRENT_FUNCTION` diff --git a/doc/index.adoc b/doc/index.adoc index 95d52c2..9873bdb 100644 --- a/doc/index.adoc +++ b/doc/index.adoc @@ -12,6 +12,8 @@ Peter Dimov :toc: left :idprefix: :docinfo: private-footer +:source-highlighter: rouge +:source-language: c++ The Boost.Assert library provides several configurable diagnostic macros similar in behavior and purpose to the standard macro `assert` from ``. @@ -30,7 +32,7 @@ include::changes.adoc[] This documentation is -* Copyright 2002, 2007, 2014, 2017, 2019, 2020 Peter Dimov +* Copyright 2002, 2007, 2014, 2017, 2019-2022 Peter Dimov * Copyright 2011 Beman Dawes * Copyright 2015 Ion Gaztañaga * Distributed under the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0]. diff --git a/doc/source_location.adoc b/doc/source_location.adoc index d3436e8..6e4cee3 100644 --- a/doc/source_location.adoc +++ b/doc/source_location.adoc @@ -1,5 +1,5 @@ //// -Copyright 2019 Peter Dimov +Copyright 2019, 2021, 2022 Peter Dimov Distributed under the Boost Software License, Version 1.0. http://www.boost.org/LICENSE_1_0.txt //// @@ -18,7 +18,71 @@ and column information. It's similar to `std::source_location` from {cpp}20, but only requires {cpp}03. The macro `BOOST_CURRENT_LOCATION` creates a `source_location` object -containing information about the current source location. +containing information about the current source location. It can be used +roughly in the same way `std::source_location::current()` can be used, +such as in the declaration of a function default argument: + +``` +#include +#include + +void f( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) +{ + std::cout << "f() called from: " << loc << std::endl; +} + +int main() +{ + f(); +} +``` + +The output of this example varies by compiler and C++ standard level, but +it's generally one of + +```none +f() called from: example.cpp:11:6 in function 'int main()' +``` +```none +f() called from: example.cpp:11:5 in function 'main' +``` +```none +f() called from: example.cpp:11 in function 'main' +``` +```none +f() called from: example.cpp:4 +``` + +This is useful if, for example, you want to declare a function that throws +an exception, such that the source location of the caller is attached to +the thrown exception: + +``` +BOOST_NORETURN BOOST_NOINLINE void throw_invalid_argument( + char const* message, + boost::source_location const& loc = BOOST_CURRENT_LOCATION ) +{ + boost::throw_exception( std::invalid_argument( message ), loc ); +} +``` + +Now you could use this helper function in, say, the implementation of +`at` to signal an index that is out of range: + +``` +T& my_class::at( size_t i ) +{ + if( i >= size() ) throw_invalid_argument( "index out of range" ); + return data()[ i ]; +} +``` + +This would attach the source location of the line in `at` that calls +`throw_invalid_argument` to the thrown exception. + +Note that if instead you use `BOOST_THROW_EXCEPTION` in +`throw_invalid_argument`, the location will be that of +`throw_invalid_argument` and not of its caller. ## Synopsis @@ -28,24 +92,26 @@ namespace boost struct source_location { - constexpr source_location() noexcept; - constexpr source_location(char const* file, uint_least32_t line, - char const* function, uint_least32_t column = 0) noexcept; - - constexpr char const* file_name() const noexcept; - constexpr char const* function_name() const noexcept; - constexpr uint_least32_t line() const noexcept; - constexpr uint_least32_t column() const noexcept; + constexpr source_location() noexcept; + constexpr source_location( char const* file, uint_least32_t line, + char const* function, uint_least32_t column = 0 ) noexcept; + constexpr source_location( std::source_location const& loc ) noexcept; + + constexpr char const* file_name() const noexcept; + constexpr char const* function_name() const noexcept; + constexpr uint_least32_t line() const noexcept; + constexpr uint_least32_t column() const noexcept; + + std::string to_string() const; }; template std::basic_ostream & - operator<<( std::basic_ostream & os, source_location const & loc ); + operator<<( std::basic_ostream & os, source_location const & loc ); } // namespace boost -#define BOOST_CURRENT_LOCATION \ - ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION) +#define BOOST_CURRENT_LOCATION /* see below */ ``` ## source_location @@ -55,44 +121,62 @@ constexpr source_location() noexcept; ``` Effects: :: Constructs a `source_location` object for which `file_name()` -and `function_name()` return `"(unknown)"`, and `line()` and `column()` -return `0`. +and `function_name()` return `""`, and `line()` and `column()` return `0`. ``` -constexpr source_location(char const* file, uint_least32_t line, - char const* function, uint_least32_t column = 0) noexcept; +constexpr source_location( char const* file, uint_least32_t line, + char const* function, uint_least32_t column = 0 ) noexcept; ``` Effects: :: Constructs a `source_location` object for which `file_name()` returns `file`, `function_name()` returns `function`, `line()` returns the `line` argument and `column()` returns the `column` argument. +``` +constexpr source_location( std::source_location const& loc ) noexcept; +``` + +Effects: :: Constructs a `source_location` object for which `file_name()` +returns `loc.file_name()`, `function_name()` returns `loc.function_name()`, +`line()` returns `loc.line()` and `column()` returns `loc.column()`. + +## to_string + +``` +std::string to_string() const; +``` + +Returns: :: + a string representation of `*this`. + ## operator<< ``` template std::basic_ostream & - operator<<( std::basic_ostream & os, source_location const & loc ); + operator<<( std::basic_ostream & os, source_location const & loc ); ``` -Effects: :: Outputs a string representation of `loc` to `os`. -Returns: :: `os`. +Effects: :: `os << loc.to_string()`. +Returns: :: + `os`. ## BOOST_CURRENT_LOCATION -When `BOOST_DISABLE_CURRENT_LOCATION` is not defined, the definition of +When `BOOST_DISABLE_CURRENT_LOCATION` is defined, the definition of `BOOST_CURRENT_LOCATION` is: -``` -#define BOOST_CURRENT_LOCATION \ - ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION) -``` - -Otherwise, `BOOST_CURRENT_LOCATION` is defined as: - ``` #define BOOST_CURRENT_LOCATION ::boost::source_location() ``` This allows producing executables that contain no identifying information, for security reasons. + +Otherwise, `BOOST_CURRENT_LOCATION` is defined as the approximate equivalent +of + +``` +#define BOOST_CURRENT_LOCATION \ + ::boost::source_location(::std::source_location::current()) +``` diff --git a/extra/boost_assert.natvis b/extra/boost_assert.natvis new file mode 100644 index 0000000..56bc7eb --- /dev/null +++ b/extra/boost_assert.natvis @@ -0,0 +1,14 @@ + + + + + {function_,sb} @ {file_,sb}:{line_} + + file_,sb + line_ + column_ + function_,sb + + + + diff --git a/include/boost/assert.hpp b/include/boost/assert.hpp index 9650d7a..48c9bcc 100644 --- a/include/boost/assert.hpp +++ b/include/boost/assert.hpp @@ -46,7 +46,13 @@ namespace boost { +#if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) + BOOST_NORETURN +#endif void assertion_failed(char const * expr, char const * function, char const * file, long line); // user defined +#if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) + BOOST_NORETURN +#endif void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line); // user defined } // namespace boost diff --git a/include/boost/assert/source_location.hpp b/include/boost/assert/source_location.hpp index c6c3e78..3c2d60e 100644 --- a/include/boost/assert/source_location.hpp +++ b/include/boost/assert/source_location.hpp @@ -1,16 +1,25 @@ #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED #define BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED -// http://www.boost.org/libs/assert +// http://www.boost.org/libs/assert // -// Copyright 2019 Peter Dimov -// Distributed under the Boost Software License, Version 1.0. -// http://www.boost.org/LICENSE_1_0.txt +// Copyright 2019, 2021 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt -#include #include #include +#include +#include +#include + +#if !defined(BOOST_NO_IOSTREAM) #include +#endif + +#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L +# include +#endif namespace boost { @@ -26,7 +35,7 @@ struct source_location public: - BOOST_CONSTEXPR source_location() BOOST_NOEXCEPT: file_( "(unknown)" ), function_( "(unknown)" ), line_( 0 ), column_( 0 ) + BOOST_CONSTEXPR source_location() BOOST_NOEXCEPT: file_( "" ), function_( "" ), line_( 0 ), column_( 0 ) { } @@ -34,6 +43,14 @@ struct source_location { } +#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L + + BOOST_CONSTEXPR source_location( std::source_location const& loc ) BOOST_NOEXCEPT: file_( loc.file_name() ), function_( loc.function_name() ), line_( loc.line() ), column_( loc.column() ) + { + } + +#endif + BOOST_CONSTEXPR char const * file_name() const BOOST_NOEXCEPT { return file_; @@ -53,46 +70,134 @@ struct source_location { return column_; } -}; -template std::basic_ostream & operator<<( std::basic_ostream & os, source_location const & loc ) -{ - os.width( 0 ); +#if defined(BOOST_MSVC) +# pragma warning( push ) +# pragma warning( disable: 4996 ) +#endif - if( loc.line() == 0 ) - { - os << "(unknown source location)"; - } - else +#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) ) +# define BOOST_ASSERT_SNPRINTF(buffer, format, arg) std::sprintf(buffer, format, arg) +#else +# define BOOST_ASSERT_SNPRINTF(buffer, format, arg) std::snprintf(buffer, sizeof(buffer)/sizeof(buffer[0]), format, arg) +#endif + + std::string to_string() const { - os << loc.file_name() << ':' << loc.line(); + unsigned long ln = line(); - if( loc.column() ) + if( ln == 0 ) { - os << ':' << loc.column(); + return "(unknown source location)"; } - os << ": in function '" << loc.function_name() << '\''; + std::string r = file_name(); + + char buffer[ 16 ]; + + BOOST_ASSERT_SNPRINTF( buffer, ":%lu", ln ); + r += buffer; + + unsigned long co = column(); + + if( co ) + { + BOOST_ASSERT_SNPRINTF( buffer, ":%lu", co ); + r += buffer; + } + + char const* fn = function_name(); + + if( *fn != 0 ) + { + r += " in function '"; + r += fn; + r += '\''; + } + + return r; } +#undef BOOST_ASSERT_SNPRINTF + +#if defined(BOOST_MSVC) +# pragma warning( pop ) +#endif + + inline friend bool operator==( source_location const& s1, source_location const& s2 ) BOOST_NOEXCEPT + { + return std::strcmp( s1.file_, s2.file_ ) == 0 && std::strcmp( s1.function_, s2.function_ ) == 0 && s1.line_ == s2.line_ && s1.column_ == s2.column_; + } + + inline friend bool operator!=( source_location const& s1, source_location const& s2 ) BOOST_NOEXCEPT + { + return !( s1 == s2 ); + } +}; + +#if !defined(BOOST_NO_IOSTREAM) + +template std::basic_ostream & operator<<( std::basic_ostream & os, source_location const & loc ) +{ + os << loc.to_string(); return os; } +#endif + } // namespace boost -#if defined( BOOST_DISABLE_CURRENT_LOCATION ) +#if defined(BOOST_DISABLE_CURRENT_LOCATION) + +# define BOOST_CURRENT_LOCATION ::boost::source_location() + +#elif defined(BOOST_MSVC) && BOOST_MSVC >= 1935 + +# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCSIG(), __builtin_COLUMN()) + +#elif defined(BOOST_MSVC) && BOOST_MSVC >= 1926 + +// std::source_location::current() is available in -std:c++20, but fails with consteval errors before 19.31, and doesn't produce +// the correct result under 19.31, so prefer the built-ins +# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN()) + +#elif defined(BOOST_MSVC) + +// __LINE__ is not a constant expression under /ZI (edit and continue) for 1925 and before + +# define BOOST_CURRENT_LOCATION_IMPL_1(x) BOOST_CURRENT_LOCATION_IMPL_2(x) +# define BOOST_CURRENT_LOCATION_IMPL_2(x) (x##0 / 10) + +# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, BOOST_CURRENT_LOCATION_IMPL_1(__LINE__), "") + +#elif defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L && !defined(__NVCC__) + +// Under nvcc, __builtin_source_location is not constexpr +// https://github.com/boostorg/assert/issues/32 + +# define BOOST_CURRENT_LOCATION ::boost::source_location(::std::source_location::current()) + +#elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION >= 90000 + +# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN()) + +#elif defined(BOOST_GCC) && BOOST_GCC >= 80000 + +// The built-ins are available in 4.8+, but are not constant expressions until 7 +// In addition, reproducible builds require -ffile-prefix-map, which is GCC 8 +// https://github.com/boostorg/assert/issues/38 -# define BOOST_CURRENT_LOCATION ::boost::source_location() +# define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION()) -#elif defined(__clang_analyzer__) +#elif defined(BOOST_GCC) && BOOST_GCC >= 50000 -// Cast to char const* to placate clang-tidy -// https://bugs.llvm.org/show_bug.cgi?id=28480 -# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, static_cast(BOOST_CURRENT_FUNCTION)) +// __PRETTY_FUNCTION__ is allowed outside functions under GCC, but 4.x suffers from codegen bugs +# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, __PRETTY_FUNCTION__) #else -# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION) +// __func__ macros aren't allowed outside functions, but BOOST_CURRENT_LOCATION is +# define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, "") #endif diff --git a/meta/libraries.json b/meta/libraries.json index 8588d3d..a8ead08 100644 --- a/meta/libraries.json +++ b/meta/libraries.json @@ -9,7 +9,8 @@ ], "description": "Customizable assert macros.", "category": [ - "Correctness" + "Correctness", + "Error-handling" ], "cxxstd": "03" } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d6be2c9..8703c22 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,8 +8,4 @@ if(HAVE_BOOST_TEST) boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::assert Boost::core) -if(BOOST_SUPERPROJECT_VERSION) - boost_test(SOURCES check_cmake_version.cpp ARGUMENTS ${PROJECT_VERSION} LINK_LIBRARIES Boost::core Boost::config) -endif() - endif() diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 0e935b6..9894dc1 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -9,12 +9,16 @@ import testing ; project : requirements + /boost/core//boost_core + extra msvc:on clang:on gcc:on gcc:-Wshadow - gcc-4.4.7:-Wno-sign-compare ; + gcc-4.4.7:-Wno-sign-compare + gcc-4.4:-Wno-sign-compare +; run assert_test.cpp ; run current_function_test.cpp @@ -38,3 +42,6 @@ run current_function_test2.cpp ; run source_location_test.cpp ; run source_location_test2.cpp ; run source_location_test3.cpp ; +run source_location_test4.cpp ; +run source_location_test5.cpp ; +run source_location_test6.cpp ; diff --git a/test/cmake_install_test/CMakeLists.txt b/test/cmake_install_test/CMakeLists.txt index 33510df..b8b5518 100644 --- a/test/cmake_install_test/CMakeLists.txt +++ b/test/cmake_install_test/CMakeLists.txt @@ -14,4 +14,4 @@ target_link_libraries(main Boost::assert) enable_testing() add_test(NAME main COMMAND main) -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) +add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) diff --git a/test/cmake_subdir_test/CMakeLists.txt b/test/cmake_subdir_test/CMakeLists.txt index 6a159a1..6af7005 100644 --- a/test/cmake_subdir_test/CMakeLists.txt +++ b/test/cmake_subdir_test/CMakeLists.txt @@ -15,4 +15,4 @@ target_link_libraries(main Boost::assert) enable_testing() add_test(NAME main COMMAND main) -add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) +add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) diff --git a/test/source_location_test.cpp b/test/source_location_test.cpp index f94e230..e3e7311 100644 --- a/test/source_location_test.cpp +++ b/test/source_location_test.cpp @@ -4,27 +4,78 @@ #include #include +#include + +static char const* adjust_filename( char const* file ) +{ +#if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20210300 + + char const* fn = std::strrchr( file, '/' ); + return fn? fn + 1: file; + +#else + + return file; + +#endif +} int main() { { boost::source_location loc; - BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" ); - BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" ); + BOOST_TEST_CSTR_EQ( loc.file_name(), "" ); + BOOST_TEST_CSTR_EQ( loc.function_name(), "" ); BOOST_TEST_EQ( loc.line(), 0 ); BOOST_TEST_EQ( loc.column(), 0 ); } { - boost::source_location loc = BOOST_CURRENT_LOCATION; - + boost::source_location loc( __FILE__, __LINE__, "main()" ); BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ ); - BOOST_TEST_CSTR_EQ( loc.function_name(), BOOST_CURRENT_FUNCTION ); - BOOST_TEST_EQ( loc.line(), 20 ); + BOOST_TEST_EQ( loc.line(), 35 ); + BOOST_TEST_CSTR_EQ( loc.function_name(), "main()" ); BOOST_TEST_EQ( loc.column(), 0 ); } + { + boost::source_location loc( "file", 1, "main()", 2 ); + + BOOST_TEST_CSTR_EQ( loc.file_name(), "file" ); + BOOST_TEST_EQ( loc.line(), 1 ); + BOOST_TEST_CSTR_EQ( loc.function_name(), "main()" ); + BOOST_TEST_EQ( loc.column(), 2 ); + } + + { + boost::source_location loc = BOOST_CURRENT_LOCATION; + + BOOST_TEST_CSTR_EQ( loc.file_name(), adjust_filename(__FILE__) ); + BOOST_TEST_EQ( loc.line(), 53 ); + } + + { + BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION; + + BOOST_TEST_CSTR_EQ( loc.file_name(), adjust_filename(__FILE__) ); + BOOST_TEST_EQ( loc.line(), 60 ); + } + +#if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L + + { + std::source_location loc = std::source_location::current(); + boost::source_location loc2 = loc; + + BOOST_TEST_CSTR_EQ( loc2.file_name(), loc.file_name() ); + BOOST_TEST_CSTR_EQ( loc2.function_name(), loc.function_name() ); + BOOST_TEST_EQ( loc2.line(), loc.line() ); + BOOST_TEST_EQ( loc2.column(), loc.column() ); + } + +#endif + return boost::report_errors(); } diff --git a/test/source_location_test2.cpp b/test/source_location_test2.cpp index e21e3f6..071b732 100644 --- a/test/source_location_test2.cpp +++ b/test/source_location_test2.cpp @@ -12,8 +12,8 @@ int main() { boost::source_location loc; - BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" ); - BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" ); + BOOST_TEST_CSTR_EQ( loc.file_name(), "" ); + BOOST_TEST_CSTR_EQ( loc.function_name(), "" ); BOOST_TEST_EQ( loc.line(), 0 ); BOOST_TEST_EQ( loc.column(), 0 ); } @@ -21,9 +21,8 @@ int main() { boost::source_location loc = BOOST_CURRENT_LOCATION; - - BOOST_TEST_CSTR_EQ( loc.file_name(), "(unknown)" ); - BOOST_TEST_CSTR_EQ( loc.function_name(), "(unknown)" ); + BOOST_TEST_CSTR_EQ( loc.file_name(), "" ); + BOOST_TEST_CSTR_EQ( loc.function_name(), "" ); BOOST_TEST_EQ( loc.line(), 0 ); BOOST_TEST_EQ( loc.column(), 0 ); } diff --git a/test/source_location_test3.cpp b/test/source_location_test3.cpp index 72a2289..810c3ee 100644 --- a/test/source_location_test3.cpp +++ b/test/source_location_test3.cpp @@ -1,29 +1,88 @@ -// Copyright 2020 Peter Dimov +// Copyright 2020, 2021 Peter Dimov // Distributed under the Boost Software License, Version 1.0. // http://www.boost.org/LICENSE_1_0.txt #include #include #include +#include + +static char const* adjust_filename( char const* file ) +{ +#if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20210300 + + char const* fn = std::strrchr( file, '/' ); + return fn? fn + 1: file; + +#else + + return file; + +#endif +} int main() { { boost::source_location loc; + BOOST_TEST_EQ( loc.to_string(), std::string( "(unknown source location)" ) ); + + std::ostringstream os; + os << loc; + + BOOST_TEST_EQ( os.str(), loc.to_string() ); + } + + { + boost::source_location loc( "file", 5, "" ); + BOOST_TEST_EQ( loc.to_string(), std::string( "file:5" ) ); + + std::ostringstream os; + os << loc; + + BOOST_TEST_EQ( os.str(), loc.to_string() ); + } + + { + boost::source_location loc( "file", 7, "main()" ); + BOOST_TEST_EQ( loc.to_string(), std::string( "file:7 in function 'main()'" ) ); + + std::ostringstream os; + os << loc; + + BOOST_TEST_EQ( os.str(), loc.to_string() ); + } + + { + boost::source_location loc( "file", 11, "main()", 13 ); + BOOST_TEST_EQ( loc.to_string(), std::string( "file:11:13 in function 'main()'" ) ); std::ostringstream os; os << loc; - BOOST_TEST_EQ( os.str(), std::string( "(unknown source location)" ) ); + BOOST_TEST_EQ( os.str(), loc.to_string() ); + } + + { + boost::source_location loc( "file", 17, "", 19 ); + BOOST_TEST_EQ( loc.to_string(), std::string( "file:17:19" ) ); + + std::ostringstream os; + os << loc; + + BOOST_TEST_EQ( os.str(), loc.to_string() ); } { boost::source_location loc = BOOST_CURRENT_LOCATION; + std::string prefix = std::string( adjust_filename(__FILE__) ) + ":77"; + BOOST_TEST_EQ( loc.to_string().substr( 0, prefix.size() ), prefix ); + std::ostringstream os; os << loc; - BOOST_TEST_EQ( os.str(), std::string( __FILE__ ) + ":21: in function '" + BOOST_CURRENT_FUNCTION + "'" ); + BOOST_TEST_EQ( os.str(), loc.to_string() ); } return boost::report_errors(); diff --git a/test/source_location_test4.cpp b/test/source_location_test4.cpp new file mode 100644 index 0000000..1242314 --- /dev/null +++ b/test/source_location_test4.cpp @@ -0,0 +1,59 @@ +// Copyright 2022 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include + +static char const* adjust_filename( char const* file ) +{ +#if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20210300 + + char const* fn = std::strrchr( file, '/' ); + return fn? fn + 1: file; + +#else + + return file; + +#endif +} + +boost::source_location s_loc = BOOST_CURRENT_LOCATION; + +BOOST_STATIC_CONSTEXPR boost::source_location c_loc = BOOST_CURRENT_LOCATION; + +boost::source_location f( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) +{ + return loc; +} + +int main() +{ + { + BOOST_TEST_CSTR_EQ( s_loc.file_name(), adjust_filename(__FILE__) ); + BOOST_TEST_EQ( s_loc.line(), 24 ); + +#if defined(BOOST_GCC) && BOOST_GCC < 90000 + // '__static_initialization_and_destruction_0' +#else + BOOST_TEST_CSTR_EQ( s_loc.function_name(), "" ); +#endif + } + + { + BOOST_TEST_CSTR_EQ( c_loc.file_name(), adjust_filename(__FILE__) ); + BOOST_TEST_EQ( c_loc.line(), 26 ); + } + + { + boost::source_location loc = f(); + + BOOST_TEST_CSTR_EQ( loc.file_name(), adjust_filename(__FILE__) ); + BOOST_TEST( loc.line() == 28 || loc.line() == 52 ); + } + + return boost::report_errors(); +} diff --git a/test/source_location_test5.cpp b/test/source_location_test5.cpp new file mode 100644 index 0000000..ef8a0dc --- /dev/null +++ b/test/source_location_test5.cpp @@ -0,0 +1,44 @@ +// Copyright 2022 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +// Reduced from a boost::system::result test; codegen bug +// in GCC < 5 which is somehow triggered by __PRETTY_FUNCTION__ +// and throwing an exception + +#include +#include +#include + +template class result +{ +private: + + bool has_value_; + T value_; + +public: + + result(): has_value_( false ), value_() + { + } + + T value( boost::source_location const& /*loc*/ = BOOST_CURRENT_LOCATION ) const + { + if( has_value_ ) + { + return value_; + } + else + { + throw std::exception(); + } + } +}; + +int main() +{ + result r; + BOOST_TEST_THROWS( r.value(), std::exception ); + return boost::report_errors(); +} diff --git a/test/source_location_test6.cpp b/test/source_location_test6.cpp new file mode 100644 index 0000000..3153597 --- /dev/null +++ b/test/source_location_test6.cpp @@ -0,0 +1,23 @@ +// Copyright 2019 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include + +int main() +{ + { + boost::source_location loc, loc2; + + BOOST_TEST_EQ( loc, loc2 ); + + boost::source_location loc3 = BOOST_CURRENT_LOCATION; + boost::source_location loc4( loc3 ); + + BOOST_TEST_EQ( loc3, loc4 ); + BOOST_TEST_NE( loc3, loc ); + } + + return boost::report_errors(); +}