├── .drone.jsonnet ├── .drone ├── drone.bat └── drone.sh ├── .gitattributes ├── .github └── workflows │ └── ci.yml ├── .travis.yml ├── CMakeLists.txt ├── README.md ├── appveyor.yml ├── build.jam ├── doc ├── .gitignore ├── Jamfile ├── assert.adoc ├── changes.adoc ├── current_function.adoc ├── index-docinfo-footer.html ├── index.adoc └── source_location.adoc ├── extra └── boost_assert.natvis ├── include └── boost │ ├── assert.hpp │ ├── assert │ └── source_location.hpp │ └── current_function.hpp ├── index.html ├── meta └── libraries.json └── test ├── CMakeLists.txt ├── Jamfile.v2 ├── assert_is_void_test.cpp ├── assert_msg_test2.cpp ├── assert_test.cpp ├── assert_test2.cpp ├── check_cmake_version.cpp ├── cmake_install_test ├── CMakeLists.txt └── main.cpp ├── cmake_subdir_test ├── CMakeLists.txt └── main.cpp ├── current_function_test.cpp ├── current_function_test2.cpp ├── exp ├── assert_exp_test.cpp ├── assert_msg_exp_test.cpp ├── verify_exp_test.cpp └── verify_msg_exp_test.cpp ├── quick.cpp ├── source_location_test.cpp ├── source_location_test2.cpp ├── source_location_test3.cpp ├── source_location_test4.cpp ├── source_location_test5.cpp ├── source_location_test6.cpp └── verify_test.cpp /.drone.jsonnet: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # https://www.boost.org/LICENSE_1_0.txt 4 | 5 | local library = "assert"; 6 | 7 | local triggers = 8 | { 9 | branch: [ "master", "develop", "feature/*" ] 10 | }; 11 | 12 | local ubsan = { UBSAN: '1', UBSAN_OPTIONS: 'print_stacktrace=1' }; 13 | local asan = { ASAN: '1' }; 14 | 15 | local linux_pipeline(name, image, environment, packages = "", sources = [], arch = "amd64") = 16 | { 17 | name: name, 18 | kind: "pipeline", 19 | type: "docker", 20 | trigger: triggers, 21 | platform: 22 | { 23 | os: "linux", 24 | arch: arch 25 | }, 26 | steps: 27 | [ 28 | { 29 | name: "everything", 30 | image: image, 31 | environment: environment, 32 | commands: 33 | [ 34 | 'set -e', 35 | 'uname -a', 36 | 'echo $DRONE_STAGE_MACHINE', 37 | 'wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -', 38 | ] + 39 | (if sources != [] then [ ('apt-add-repository "' + source + '"') for source in sources ] else []) + 40 | (if packages != "" then [ 'apt-get update', 'apt-get -y install ' + packages ] else []) + 41 | [ 42 | 'export LIBRARY=' + library, 43 | './.drone/drone.sh', 44 | ] 45 | } 46 | ] 47 | }; 48 | 49 | local macos_pipeline(name, environment, xcode_version = "12.2", osx_version = "catalina", arch = "amd64") = 50 | { 51 | name: name, 52 | kind: "pipeline", 53 | type: "exec", 54 | trigger: triggers, 55 | platform: { 56 | "os": "darwin", 57 | "arch": arch 58 | }, 59 | node: { 60 | "os": osx_version 61 | }, 62 | steps: [ 63 | { 64 | name: "everything", 65 | environment: environment + { "DEVELOPER_DIR": "/Applications/Xcode-" + xcode_version + ".app/Contents/Developer" }, 66 | commands: 67 | [ 68 | 'export LIBRARY=' + library, 69 | './.drone/drone.sh', 70 | ] 71 | } 72 | ] 73 | }; 74 | 75 | local windows_pipeline(name, image, environment, arch = "amd64") = 76 | { 77 | name: name, 78 | kind: "pipeline", 79 | type: "docker", 80 | trigger: triggers, 81 | platform: 82 | { 83 | os: "windows", 84 | arch: arch 85 | }, 86 | "steps": 87 | [ 88 | { 89 | name: "everything", 90 | image: image, 91 | environment: environment, 92 | commands: 93 | [ 94 | 'cmd /C .drone\\\\drone.bat ' + library, 95 | ] 96 | } 97 | ] 98 | }; 99 | 100 | [ 101 | linux_pipeline( 102 | "Linux 16.04 GCC 4.4", 103 | "cppalliance/droneubuntu1604:1", 104 | { TOOLSET: 'gcc', COMPILER: 'g++-4.4', CXXSTD: '98,0x' }, 105 | "g++-4.4", 106 | [ "ppa:ubuntu-toolchain-r/test" ], 107 | ), 108 | 109 | linux_pipeline( 110 | "Linux 16.04 GCC 4.6", 111 | "cppalliance/droneubuntu1604:1", 112 | { TOOLSET: 'gcc', COMPILER: 'g++-4.6', CXXSTD: '98,0x' }, 113 | "g++-4.6", 114 | [ "ppa:ubuntu-toolchain-r/test" ], 115 | ), 116 | 117 | linux_pipeline( 118 | "Linux 16.04 GCC 4.7", 119 | "cppalliance/droneubuntu1604:1", 120 | { TOOLSET: 'gcc', COMPILER: 'g++-4.7', CXXSTD: '98,0x' }, 121 | "g++-4.7", 122 | ), 123 | 124 | linux_pipeline( 125 | "Linux 16.04 GCC 4.8", 126 | "cppalliance/droneubuntu1604:1", 127 | { TOOLSET: 'gcc', COMPILER: 'g++-4.8', CXXSTD: '03,11' }, 128 | "g++-4.8", 129 | ), 130 | 131 | linux_pipeline( 132 | "Linux 16.04 GCC 4.9", 133 | "cppalliance/droneubuntu1604:1", 134 | { TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '03,11' }, 135 | "g++-4.9", 136 | ), 137 | 138 | linux_pipeline( 139 | "Linux 16.04 GCC 5* 32/64", 140 | "cppalliance/droneubuntu1604:1", 141 | { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14', ADDRMD: '32,64' }, 142 | ), 143 | 144 | linux_pipeline( 145 | "Linux 18.04 GCC 6", 146 | "cppalliance/droneubuntu1804:1", 147 | { TOOLSET: 'gcc', COMPILER: 'g++-6', CXXSTD: '03,11,14' }, 148 | "g++-6", 149 | ), 150 | 151 | linux_pipeline( 152 | "Linux 18.04 GCC 7* 32/64", 153 | "cppalliance/droneubuntu1804:1", 154 | { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17', ADDRMD: '32,64' }, 155 | ), 156 | 157 | linux_pipeline( 158 | "Linux 18.04 GCC 8", 159 | "cppalliance/droneubuntu1804:1", 160 | { TOOLSET: 'gcc', COMPILER: 'g++-8', CXXSTD: '03,11,14,17' }, 161 | "g++-8", 162 | ), 163 | 164 | linux_pipeline( 165 | "Linux 20.04 GCC 9* 32/64", 166 | "cppalliance/droneubuntu2004:1", 167 | { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' }, 168 | ), 169 | 170 | linux_pipeline( 171 | "Linux 20.04 GCC 9* ARM64", 172 | "cppalliance/droneubuntu2004:multiarch", 173 | { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' }, 174 | arch="arm64", 175 | ), 176 | 177 | linux_pipeline( 178 | "Linux 20.04 GCC 9* S390x", 179 | "cppalliance/droneubuntu2004:multiarch", 180 | { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' }, 181 | arch="s390x", 182 | ), 183 | 184 | linux_pipeline( 185 | "Linux 20.04 GCC 10", 186 | "cppalliance/droneubuntu2004:1", 187 | { TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20' }, 188 | "g++-10", 189 | ), 190 | 191 | linux_pipeline( 192 | "Linux 22.04 GCC 11* 32/64", 193 | "cppalliance/droneubuntu2204:1", 194 | { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' }, 195 | ), 196 | 197 | linux_pipeline( 198 | "Linux 22.04 GCC 12 32/64", 199 | "cppalliance/droneubuntu2204:1", 200 | { TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' }, 201 | "g++-12-multilib", 202 | ), 203 | 204 | linux_pipeline( 205 | "Linux 24.04 GCC 13* 32/64", 206 | "cppalliance/droneubuntu2404:1", 207 | { TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' }, 208 | ), 209 | 210 | linux_pipeline( 211 | "Linux 24.04 GCC 14 32/64 ASAN", 212 | "cppalliance/droneubuntu2404:1", 213 | { TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' } + asan, 214 | "g++-14-multilib", 215 | ), 216 | 217 | linux_pipeline( 218 | "Linux 24.04 GCC 14 32/64 UBSAN", 219 | "cppalliance/droneubuntu2404:1", 220 | { TOOLSET: 'gcc', COMPILER: 'g++-14', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32,64' } + ubsan, 221 | "g++-14-multilib", 222 | ), 223 | 224 | linux_pipeline( 225 | "Linux 16.04 Clang 3.5", 226 | "cppalliance/droneubuntu1604:1", 227 | { TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '03,11,14' }, 228 | "clang-3.5", 229 | ), 230 | 231 | linux_pipeline( 232 | "Linux 16.04 Clang 3.6", 233 | "cppalliance/droneubuntu1604:1", 234 | { TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '03,11,14' }, 235 | "clang-3.6", 236 | ), 237 | 238 | linux_pipeline( 239 | "Linux 16.04 Clang 3.7", 240 | "cppalliance/droneubuntu1604:1", 241 | { TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '03,11,14' }, 242 | "clang-3.7", 243 | ), 244 | 245 | linux_pipeline( 246 | "Linux 16.04 Clang 3.8", 247 | "cppalliance/droneubuntu1604:1", 248 | { TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '03,11,14' }, 249 | "clang-3.8", 250 | ), 251 | 252 | linux_pipeline( 253 | "Linux 18.04 Clang 3.9", 254 | "cppalliance/droneubuntu1804:1", 255 | { TOOLSET: 'clang', COMPILER: 'clang++-3.9', CXXSTD: '03,11,14' }, 256 | "clang-3.9", 257 | ), 258 | 259 | linux_pipeline( 260 | "Linux 18.04 Clang 4.0", 261 | "cppalliance/droneubuntu1804:1", 262 | { TOOLSET: 'clang', COMPILER: 'clang++-4.0', CXXSTD: '03,11,14' }, 263 | "clang-4.0", 264 | ), 265 | 266 | linux_pipeline( 267 | "Linux 18.04 Clang 5.0", 268 | "cppalliance/droneubuntu1804:1", 269 | { TOOLSET: 'clang', COMPILER: 'clang++-5.0', CXXSTD: '03,11,14,1z' }, 270 | "clang-5.0", 271 | ), 272 | 273 | linux_pipeline( 274 | "Linux 18.04 Clang 6.0", 275 | "cppalliance/droneubuntu1804:1", 276 | { TOOLSET: 'clang', COMPILER: 'clang++-6.0', CXXSTD: '03,11,14,17' }, 277 | "clang-6.0", 278 | ), 279 | 280 | linux_pipeline( 281 | "Linux 20.04 Clang 7", 282 | "cppalliance/droneubuntu2004:1", 283 | { TOOLSET: 'clang', COMPILER: 'clang++-7', CXXSTD: '03,11,14,17' }, 284 | "clang-7", 285 | ), 286 | 287 | linux_pipeline( 288 | "Linux 20.04 Clang 8", 289 | "cppalliance/droneubuntu2004:1", 290 | { TOOLSET: 'clang', COMPILER: 'clang++-8', CXXSTD: '03,11,14,17' }, 291 | "clang-8", 292 | ), 293 | 294 | linux_pipeline( 295 | "Linux 20.04 Clang 9", 296 | "cppalliance/droneubuntu2004:1", 297 | { TOOLSET: 'clang', COMPILER: 'clang++-9', CXXSTD: '03,11,14,17,2a' }, 298 | "clang-9", 299 | ), 300 | 301 | linux_pipeline( 302 | "Linux 20.04 Clang 10", 303 | "cppalliance/droneubuntu2004:1", 304 | { TOOLSET: 'clang', COMPILER: 'clang++-10', CXXSTD: '03,11,14,17,2a' }, 305 | "clang-10", 306 | ), 307 | 308 | linux_pipeline( 309 | "Linux 20.04 Clang 11", 310 | "cppalliance/droneubuntu2004:1", 311 | { TOOLSET: 'clang', COMPILER: 'clang++-11', CXXSTD: '03,11,14,17,2a' }, 312 | "clang-11", 313 | ), 314 | 315 | linux_pipeline( 316 | "Linux 20.04 Clang 12", 317 | "cppalliance/droneubuntu2004:1", 318 | { TOOLSET: 'clang', COMPILER: 'clang++-12', CXXSTD: '03,11,14,17,2a' }, 319 | "clang-12", 320 | ), 321 | 322 | linux_pipeline( 323 | "Linux 22.04 Clang 13", 324 | "cppalliance/droneubuntu2204:1", 325 | { TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '03,11,14,17,20' }, 326 | "clang-13", 327 | ), 328 | 329 | linux_pipeline( 330 | "Linux 22.04 Clang 14", 331 | "cppalliance/droneubuntu2204:1", 332 | { TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' }, 333 | "clang-14", 334 | ), 335 | 336 | linux_pipeline( 337 | "Linux 22.04 Clang 15", 338 | "cppalliance/droneubuntu2204:1", 339 | { TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' }, 340 | "clang-15", 341 | ), 342 | 343 | linux_pipeline( 344 | "Linux 24.04 Clang 16", 345 | "cppalliance/droneubuntu2404:1", 346 | { TOOLSET: 'clang', COMPILER: 'clang++-16', CXXSTD: '03,11,14,17,20,2b' }, 347 | "clang-16", 348 | ), 349 | 350 | linux_pipeline( 351 | "Linux 24.04 Clang 17", 352 | "cppalliance/droneubuntu2404:1", 353 | { TOOLSET: 'clang', COMPILER: 'clang++-17', CXXSTD: '03,11,14,17,20,2b' }, 354 | "clang-17", 355 | ), 356 | 357 | linux_pipeline( 358 | "Linux 24.04 Clang 18 UBSAN", 359 | "cppalliance/droneubuntu2404:1", 360 | { TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '03,11,14,17,20,2b' } + ubsan, 361 | "clang-18", 362 | ), 363 | 364 | linux_pipeline( 365 | "Linux 24.04 Clang 18 ASAN", 366 | "cppalliance/droneubuntu2404:1", 367 | { TOOLSET: 'clang', COMPILER: 'clang++-18', CXXSTD: '03,11,14,17,20,2b' } + asan, 368 | "clang-18", 369 | ), 370 | 371 | linux_pipeline( 372 | "Linux 24.10 Clang 19", 373 | "cppalliance/droneubuntu2410:1", 374 | { TOOLSET: 'clang', COMPILER: 'clang++-19', CXXSTD: '03,11,14,17,20,2b' }, 375 | "clang-19", 376 | ), 377 | 378 | macos_pipeline( 379 | "MacOS 10.15 Xcode 12.2 UBSAN", 380 | { TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + ubsan, 381 | ), 382 | 383 | macos_pipeline( 384 | "MacOS 10.15 Xcode 12.2 ASAN", 385 | { TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + asan, 386 | ), 387 | 388 | macos_pipeline( 389 | "MacOS 12.4 Xcode 13.4.1 UBSAN", 390 | { TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,20,2b' } + ubsan, 391 | xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64", 392 | ), 393 | 394 | macos_pipeline( 395 | "MacOS 12.4 Xcode 13.4.1 ASAN", 396 | { TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '11,14,17,20,2b' } + asan, 397 | xcode_version = "13.4.1", osx_version = "monterey", arch = "arm64", 398 | ), 399 | 400 | windows_pipeline( 401 | "Windows VS2015 msvc-14.0", 402 | "cppalliance/dronevs2015", 403 | { TOOLSET: 'msvc-14.0', CXXSTD: '14,latest', B2_DONT_EMBED_MANIFEST: '1' }, 404 | ), 405 | 406 | windows_pipeline( 407 | "Windows VS2017 msvc-14.1", 408 | "cppalliance/dronevs2017", 409 | { TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' }, 410 | ), 411 | 412 | windows_pipeline( 413 | "Windows VS2019 msvc-14.2", 414 | "cppalliance/dronevs2019", 415 | { TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' }, 416 | ), 417 | 418 | windows_pipeline( 419 | "Windows VS2022 msvc-14.3", 420 | "cppalliance/dronevs2022:1", 421 | { TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' }, 422 | ), 423 | ] 424 | -------------------------------------------------------------------------------- /.drone/drone.bat: -------------------------------------------------------------------------------- 1 | @REM Copyright 2022 Peter Dimov 2 | @REM Distributed under the Boost Software License, Version 1.0. 3 | @REM https://www.boost.org/LICENSE_1_0.txt 4 | 5 | @ECHO ON 6 | 7 | set LIBRARY=%1 8 | set DRONE_BUILD_DIR=%CD% 9 | 10 | set BOOST_BRANCH=develop 11 | if "%DRONE_BRANCH%" == "master" set BOOST_BRANCH=master 12 | cd .. 13 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 14 | cd boost-root 15 | git submodule update --init tools/boostdep 16 | xcopy /s /e /q %DRONE_BUILD_DIR% libs\%LIBRARY%\ 17 | python tools/boostdep/depinst/depinst.py %LIBRARY% 18 | cmd /c bootstrap 19 | b2 -d0 headers 20 | 21 | if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD% 22 | if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD% 23 | b2 -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker 24 | -------------------------------------------------------------------------------- /.drone/drone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2022 Peter Dimov 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # https://www.boost.org/LICENSE_1_0.txt 6 | 7 | set -ex 8 | export PATH=~/.local/bin:/usr/local/bin:$PATH 9 | 10 | DRONE_BUILD_DIR=$(pwd) 11 | 12 | BOOST_BRANCH=develop 13 | if [ "$DRONE_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi 14 | 15 | cd .. 16 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 17 | cd boost-root 18 | git submodule update --init tools/boostdep 19 | cp -r $DRONE_BUILD_DIR/* libs/$LIBRARY 20 | python tools/boostdep/depinst/depinst.py $LIBRARY 21 | ./bootstrap.sh 22 | ./b2 -d0 headers 23 | 24 | echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam 25 | ./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} 26 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto !eol svneol=native#text/plain 2 | *.gitattributes text svneol=native#text/plain 3 | 4 | # Scriptish formats 5 | *.bat text svneol=native#text/plain 6 | *.bsh text svneol=native#text/x-beanshell 7 | *.cgi text svneol=native#text/plain 8 | *.cmd text svneol=native#text/plain 9 | *.js text svneol=native#text/javascript 10 | *.php text svneol=native#text/x-php 11 | *.pl text svneol=native#text/x-perl 12 | *.pm text svneol=native#text/x-perl 13 | *.py text svneol=native#text/x-python 14 | *.sh eol=lf svneol=LF#text/x-sh 15 | configure eol=lf svneol=LF#text/x-sh 16 | 17 | # Image formats 18 | *.bmp binary svneol=unset#image/bmp 19 | *.gif binary svneol=unset#image/gif 20 | *.ico binary svneol=unset#image/ico 21 | *.jpeg binary svneol=unset#image/jpeg 22 | *.jpg binary svneol=unset#image/jpeg 23 | *.png binary svneol=unset#image/png 24 | *.tif binary svneol=unset#image/tiff 25 | *.tiff binary svneol=unset#image/tiff 26 | *.svg text svneol=native#image/svg%2Bxml 27 | 28 | # Data formats 29 | *.pdf binary svneol=unset#application/pdf 30 | *.avi binary svneol=unset#video/avi 31 | *.doc binary svneol=unset#application/msword 32 | *.dsp text svneol=crlf#text/plain 33 | *.dsw text svneol=crlf#text/plain 34 | *.eps binary svneol=unset#application/postscript 35 | *.gz binary svneol=unset#application/gzip 36 | *.mov binary svneol=unset#video/quicktime 37 | *.mp3 binary svneol=unset#audio/mpeg 38 | *.ppt binary svneol=unset#application/vnd.ms-powerpoint 39 | *.ps binary svneol=unset#application/postscript 40 | *.psd binary svneol=unset#application/photoshop 41 | *.rdf binary svneol=unset#text/rdf 42 | *.rss text svneol=unset#text/xml 43 | *.rtf binary svneol=unset#text/rtf 44 | *.sln text svneol=native#text/plain 45 | *.swf binary svneol=unset#application/x-shockwave-flash 46 | *.tgz binary svneol=unset#application/gzip 47 | *.vcproj text svneol=native#text/xml 48 | *.vcxproj text svneol=native#text/xml 49 | *.vsprops text svneol=native#text/xml 50 | *.wav binary svneol=unset#audio/wav 51 | *.xls binary svneol=unset#application/vnd.ms-excel 52 | *.zip binary svneol=unset#application/zip 53 | 54 | # Text formats 55 | .htaccess text svneol=native#text/plain 56 | *.bbk text svneol=native#text/xml 57 | *.cmake text svneol=native#text/plain 58 | *.css text svneol=native#text/css 59 | *.dtd text svneol=native#text/xml 60 | *.htm text svneol=native#text/html 61 | *.html text svneol=native#text/html 62 | *.ini text svneol=native#text/plain 63 | *.log text svneol=native#text/plain 64 | *.mak text svneol=native#text/plain 65 | *.qbk text svneol=native#text/plain 66 | *.rst text svneol=native#text/plain 67 | *.sql text svneol=native#text/x-sql 68 | *.txt text svneol=native#text/plain 69 | *.xhtml text svneol=native#text/xhtml%2Bxml 70 | *.xml text svneol=native#text/xml 71 | *.xsd text svneol=native#text/xml 72 | *.xsl text svneol=native#text/xml 73 | *.xslt text svneol=native#text/xml 74 | *.xul text svneol=native#text/xul 75 | *.yml text svneol=native#text/plain 76 | boost-no-inspect text svneol=native#text/plain 77 | CHANGES text svneol=native#text/plain 78 | COPYING text svneol=native#text/plain 79 | INSTALL text svneol=native#text/plain 80 | Jamfile text svneol=native#text/plain 81 | Jamroot text svneol=native#text/plain 82 | Jamfile.v2 text svneol=native#text/plain 83 | Jamrules text svneol=native#text/plain 84 | Makefile* text svneol=native#text/plain 85 | README text svneol=native#text/plain 86 | TODO text svneol=native#text/plain 87 | 88 | # Code formats 89 | *.c text svneol=native#text/plain 90 | *.cpp text svneol=native#text/plain 91 | *.h text svneol=native#text/plain 92 | *.hpp text svneol=native#text/plain 93 | *.ipp text svneol=native#text/plain 94 | *.tpp text svneol=native#text/plain 95 | *.jam text svneol=native#text/plain 96 | *.java text svneol=native#text/plain 97 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | - develop 9 | - feature/** 10 | 11 | env: 12 | UBSAN_OPTIONS: print_stacktrace=1 13 | 14 | jobs: 15 | posix: 16 | strategy: 17 | fail-fast: false 18 | matrix: 19 | include: 20 | - toolset: gcc-4.8 21 | cxxstd: "03,11" 22 | container: ubuntu:18.04 23 | os: ubuntu-latest 24 | install: g++-4.8 25 | - toolset: gcc-5 26 | cxxstd: "03,11,14,1z" 27 | container: ubuntu:18.04 28 | os: ubuntu-latest 29 | install: g++-5 30 | - toolset: gcc-6 31 | cxxstd: "03,11,14,1z" 32 | container: ubuntu:18.04 33 | os: ubuntu-latest 34 | install: g++-6 35 | - toolset: gcc-7 36 | cxxstd: "03,11,14,17" 37 | container: ubuntu:20.04 38 | os: ubuntu-latest 39 | install: g++-7 40 | - toolset: gcc-8 41 | cxxstd: "03,11,14,17,2a" 42 | container: ubuntu:20.04 43 | os: ubuntu-latest 44 | install: g++-8 45 | - toolset: gcc-9 46 | cxxstd: "03,11,14,17,2a" 47 | container: ubuntu:20.04 48 | os: ubuntu-latest 49 | - toolset: gcc-10 50 | cxxstd: "03,11,14,17,2a" 51 | container: ubuntu:20.04 52 | os: ubuntu-latest 53 | install: g++-10 54 | - toolset: gcc-11 55 | cxxstd: "03,11,14,17,2a" 56 | os: ubuntu-22.04 57 | install: g++-11 58 | - toolset: gcc-12 59 | cxxstd: "03,11,14,17,20,2b" 60 | os: ubuntu-22.04 61 | install: g++-12 62 | - toolset: gcc-13 63 | cxxstd: "03,11,14,17,20,2b" 64 | os: ubuntu-latest 65 | container: ubuntu:24.04 66 | install: g++-13 67 | - toolset: gcc-14 68 | cxxstd: "03,11,14,17,20,2b" 69 | os: ubuntu-latest 70 | container: ubuntu:24.04 71 | install: g++-14 72 | - toolset: clang 73 | compiler: clang++-3.9 74 | cxxstd: "03,11,14" 75 | container: ubuntu:18.04 76 | os: ubuntu-latest 77 | install: clang-3.9 78 | - toolset: clang 79 | compiler: clang++-4.0 80 | cxxstd: "03,11,14" 81 | container: ubuntu:18.04 82 | os: ubuntu-latest 83 | install: clang-4.0 84 | - toolset: clang 85 | compiler: clang++-5.0 86 | cxxstd: "03,11,14,1z" 87 | container: ubuntu:18.04 88 | os: ubuntu-latest 89 | install: clang-5.0 90 | - toolset: clang 91 | compiler: clang++-6.0 92 | cxxstd: "03,11,14,17" 93 | container: ubuntu:20.04 94 | os: ubuntu-latest 95 | install: clang-6.0 96 | - toolset: clang 97 | compiler: clang++-7 98 | cxxstd: "03,11,14,17" 99 | container: ubuntu:20.04 100 | os: ubuntu-latest 101 | install: clang-7 102 | - toolset: clang 103 | compiler: clang++-8 104 | cxxstd: "03,11,14,17,2a" 105 | container: ubuntu:20.04 106 | os: ubuntu-latest 107 | install: clang-8 108 | - toolset: clang 109 | compiler: clang++-9 110 | cxxstd: "03,11,14,17,2a" 111 | container: ubuntu:20.04 112 | os: ubuntu-latest 113 | install: clang-9 114 | - toolset: clang 115 | compiler: clang++-10 116 | cxxstd: "03,11,14,17,2a" 117 | container: ubuntu:20.04 118 | os: ubuntu-latest 119 | install: clang-10 120 | - toolset: clang 121 | compiler: clang++-11 122 | cxxstd: "03,11,14,17,2a" 123 | container: ubuntu:20.04 124 | os: ubuntu-latest 125 | install: clang-11 126 | - toolset: clang 127 | compiler: clang++-12 128 | cxxstd: "03,11,14,17,2a" 129 | container: ubuntu:20.04 130 | os: ubuntu-latest 131 | install: clang-12 132 | - toolset: clang 133 | compiler: clang++-13 134 | cxxstd: "03,11,14,17,20,2b" 135 | container: ubuntu:22.04 136 | os: ubuntu-latest 137 | install: clang-13 138 | - toolset: clang 139 | compiler: clang++-14 140 | cxxstd: "03,11,14,17,20,2b" 141 | container: ubuntu:22.04 142 | os: ubuntu-latest 143 | install: clang-14 144 | - toolset: clang 145 | compiler: clang++-15 146 | cxxstd: "03,11,14,17,20,2b" 147 | container: ubuntu:22.04 148 | os: ubuntu-latest 149 | install: clang-15 150 | - toolset: clang 151 | compiler: clang++-16 152 | cxxstd: "03,11,14,17,20,2b" 153 | container: ubuntu:24.04 154 | os: ubuntu-latest 155 | install: clang-16 156 | - toolset: clang 157 | compiler: clang++-17 158 | cxxstd: "03,11,14,17,20,2b" 159 | container: ubuntu:24.04 160 | os: ubuntu-latest 161 | install: clang-17 162 | - toolset: clang 163 | compiler: clang++-18 164 | cxxstd: "03,11,14,17,20,2b" 165 | container: ubuntu:24.04 166 | os: ubuntu-latest 167 | install: clang-18 168 | - toolset: clang 169 | compiler: clang++-19 170 | cxxstd: "03,11,14,17,20,2b" 171 | container: ubuntu:24.10 172 | os: ubuntu-latest 173 | install: clang-19 174 | - toolset: clang 175 | cxxstd: "03,11,14,17,20,2b" 176 | os: macos-13 177 | - toolset: clang 178 | cxxstd: "03,11,14,17,20,2b" 179 | os: macos-14 180 | - toolset: clang 181 | cxxstd: "03,11,14,17,20,2b" 182 | os: macos-15 183 | 184 | runs-on: ${{matrix.os}} 185 | 186 | container: 187 | image: ${{matrix.container}} 188 | volumes: 189 | - /node20217:/node20217:rw,rshared 190 | - ${{ startsWith(matrix.container, 'ubuntu:1') && '/node20217:/__e/node20:ro,rshared' || ' ' }} 191 | 192 | defaults: 193 | run: 194 | shell: bash 195 | 196 | steps: 197 | - name: Setup container environment 198 | if: matrix.container 199 | run: | 200 | apt-get update 201 | apt-get -y install sudo python3 git g++ curl xz-utils 202 | 203 | - name: Install nodejs20glibc2.17 204 | if: ${{ startsWith( matrix.container, 'ubuntu:1' ) }} 205 | run: | 206 | curl -LO https://archives.boost.io/misc/node/node-v20.9.0-linux-x64-glibc-217.tar.xz 207 | tar -xf node-v20.9.0-linux-x64-glibc-217.tar.xz --strip-components 1 -C /node20217 208 | ldd /__e/node20/bin/node 209 | 210 | - uses: actions/checkout@v4 211 | 212 | - name: Install packages 213 | if: matrix.install 214 | run: | 215 | sudo apt-get update 216 | sudo apt-get -y install ${{matrix.install}} 217 | 218 | - name: Setup Boost 219 | run: | 220 | echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY 221 | LIBRARY=${GITHUB_REPOSITORY#*/} 222 | echo LIBRARY: $LIBRARY 223 | echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV 224 | echo GITHUB_BASE_REF: $GITHUB_BASE_REF 225 | echo GITHUB_REF: $GITHUB_REF 226 | REF=${GITHUB_BASE_REF:-$GITHUB_REF} 227 | REF=${REF#refs/heads/} 228 | echo REF: $REF 229 | BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true 230 | echo BOOST_BRANCH: $BOOST_BRANCH 231 | cd .. 232 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 233 | cd boost-root 234 | cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY 235 | git submodule update --init tools/boostdep 236 | python3 tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY 237 | ./bootstrap.sh 238 | ./b2 -d0 headers 239 | 240 | - name: Create user-config.jam 241 | if: matrix.compiler 242 | run: | 243 | echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam 244 | 245 | - name: Run tests 246 | run: | 247 | cd ../boost-root 248 | ./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} variant=debug,release 249 | 250 | windows: 251 | strategy: 252 | fail-fast: false 253 | matrix: 254 | include: 255 | - toolset: msvc-14.0 256 | cxxstd: "14,latest" 257 | addrmd: 32,64 258 | os: windows-2019 259 | - toolset: msvc-14.2 260 | cxxstd: "14,17,20,latest" 261 | addrmd: 32,64 262 | os: windows-2019 263 | - toolset: msvc-14.3 264 | cxxstd: "14,17,20,latest" 265 | addrmd: 32,64 266 | os: windows-2022 267 | - toolset: clang-win 268 | cxxstd: "14,17,latest" 269 | addrmd: 32,64 270 | os: windows-2022 271 | - toolset: gcc 272 | cxxstd: "03,11,14,17,2a" 273 | addrmd: 64 274 | os: windows-2019 275 | 276 | runs-on: ${{matrix.os}} 277 | 278 | steps: 279 | - uses: actions/checkout@v4 280 | 281 | - name: Setup Boost 282 | shell: cmd 283 | run: | 284 | echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% 285 | for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi 286 | echo LIBRARY: %LIBRARY% 287 | echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% 288 | echo GITHUB_BASE_REF: %GITHUB_BASE_REF% 289 | echo GITHUB_REF: %GITHUB_REF% 290 | if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% 291 | set BOOST_BRANCH=develop 292 | for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master 293 | echo BOOST_BRANCH: %BOOST_BRANCH% 294 | cd .. 295 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 296 | cd boost-root 297 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ 298 | git submodule update --init tools/boostdep 299 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% 300 | cmd /c bootstrap 301 | b2 -d0 headers 302 | 303 | - name: Run tests 304 | shell: cmd 305 | run: | 306 | cd ../boost-root 307 | b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker 308 | 309 | posix-cmake-subdir: 310 | strategy: 311 | fail-fast: false 312 | matrix: 313 | include: 314 | - os: ubuntu-22.04 315 | - os: ubuntu-24.04 316 | - os: macos-13 317 | - os: macos-14 318 | - os: macos-15 319 | 320 | runs-on: ${{matrix.os}} 321 | 322 | steps: 323 | - uses: actions/checkout@v4 324 | 325 | - name: Install packages 326 | if: matrix.install 327 | run: sudo apt-get -y install ${{matrix.install}} 328 | 329 | - name: Setup Boost 330 | run: | 331 | echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY 332 | LIBRARY=${GITHUB_REPOSITORY#*/} 333 | echo LIBRARY: $LIBRARY 334 | echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV 335 | echo GITHUB_BASE_REF: $GITHUB_BASE_REF 336 | echo GITHUB_REF: $GITHUB_REF 337 | REF=${GITHUB_BASE_REF:-$GITHUB_REF} 338 | REF=${REF#refs/heads/} 339 | echo REF: $REF 340 | BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true 341 | echo BOOST_BRANCH: $BOOST_BRANCH 342 | cd .. 343 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 344 | cd boost-root 345 | cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY 346 | git submodule update --init tools/boostdep 347 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY 348 | 349 | - name: Use library with add_subdirectory 350 | run: | 351 | cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test 352 | mkdir __build__ && cd __build__ 353 | cmake .. 354 | cmake --build . 355 | ctest --output-on-failure --no-tests=error 356 | 357 | posix-cmake-install: 358 | strategy: 359 | fail-fast: false 360 | matrix: 361 | include: 362 | - os: ubuntu-22.04 363 | - os: ubuntu-24.04 364 | - os: macos-13 365 | - os: macos-14 366 | - os: macos-15 367 | 368 | runs-on: ${{matrix.os}} 369 | 370 | steps: 371 | - uses: actions/checkout@v4 372 | 373 | - name: Install packages 374 | if: matrix.install 375 | run: sudo apt-get -y install ${{matrix.install}} 376 | 377 | - name: Setup Boost 378 | run: | 379 | echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY 380 | LIBRARY=${GITHUB_REPOSITORY#*/} 381 | echo LIBRARY: $LIBRARY 382 | echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV 383 | echo GITHUB_BASE_REF: $GITHUB_BASE_REF 384 | echo GITHUB_REF: $GITHUB_REF 385 | REF=${GITHUB_BASE_REF:-$GITHUB_REF} 386 | REF=${REF#refs/heads/} 387 | echo REF: $REF 388 | BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true 389 | echo BOOST_BRANCH: $BOOST_BRANCH 390 | cd .. 391 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 392 | cd boost-root 393 | cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY 394 | git submodule update --init tools/boostdep 395 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY 396 | 397 | - name: Configure 398 | run: | 399 | cd ../boost-root 400 | mkdir __build__ && cd __build__ 401 | cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local .. 402 | 403 | - name: Install 404 | run: | 405 | cd ../boost-root/__build__ 406 | cmake --build . --target install 407 | 408 | - name: Use the installed library 409 | run: | 410 | cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__ 411 | cmake -DCMAKE_INSTALL_PREFIX=~/.local .. 412 | cmake --build . 413 | ctest --output-on-failure --no-tests=error 414 | 415 | posix-cmake-test: 416 | strategy: 417 | fail-fast: false 418 | matrix: 419 | include: 420 | - os: ubuntu-22.04 421 | - os: ubuntu-24.04 422 | - os: macos-13 423 | - os: macos-14 424 | - os: macos-15 425 | 426 | runs-on: ${{matrix.os}} 427 | 428 | steps: 429 | - uses: actions/checkout@v4 430 | 431 | - name: Install packages 432 | if: matrix.install 433 | run: sudo apt-get -y install ${{matrix.install}} 434 | 435 | - name: Setup Boost 436 | run: | 437 | echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY 438 | LIBRARY=${GITHUB_REPOSITORY#*/} 439 | echo LIBRARY: $LIBRARY 440 | echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV 441 | echo GITHUB_BASE_REF: $GITHUB_BASE_REF 442 | echo GITHUB_REF: $GITHUB_REF 443 | REF=${GITHUB_BASE_REF:-$GITHUB_REF} 444 | REF=${REF#refs/heads/} 445 | echo REF: $REF 446 | BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true 447 | echo BOOST_BRANCH: $BOOST_BRANCH 448 | cd .. 449 | git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root 450 | cd boost-root 451 | cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY 452 | git submodule update --init tools/boostdep 453 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY 454 | 455 | - name: Configure 456 | run: | 457 | cd ../boost-root 458 | mkdir __build__ && cd __build__ 459 | cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON .. 460 | 461 | - name: Build tests 462 | run: | 463 | cd ../boost-root/__build__ 464 | cmake --build . --target tests 465 | 466 | - name: Run tests 467 | run: | 468 | cd ../boost-root/__build__ 469 | ctest --output-on-failure --no-tests=error 470 | 471 | windows-cmake-subdir: 472 | strategy: 473 | fail-fast: false 474 | matrix: 475 | include: 476 | - os: windows-2019 477 | - os: windows-2022 478 | 479 | runs-on: ${{matrix.os}} 480 | 481 | steps: 482 | - uses: actions/checkout@v4 483 | 484 | - name: Setup Boost 485 | shell: cmd 486 | run: | 487 | echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% 488 | for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi 489 | echo LIBRARY: %LIBRARY% 490 | echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% 491 | echo GITHUB_BASE_REF: %GITHUB_BASE_REF% 492 | echo GITHUB_REF: %GITHUB_REF% 493 | if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% 494 | set BOOST_BRANCH=develop 495 | for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master 496 | echo BOOST_BRANCH: %BOOST_BRANCH% 497 | cd .. 498 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 499 | cd boost-root 500 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ 501 | git submodule update --init tools/boostdep 502 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% 503 | 504 | - name: Use library with add_subdirectory (Debug) 505 | shell: cmd 506 | run: | 507 | cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test 508 | mkdir __build__ && cd __build__ 509 | cmake .. 510 | cmake --build . --config Debug 511 | ctest --output-on-failure --no-tests=error -C Debug 512 | 513 | - name: Use library with add_subdirectory (Release) 514 | shell: cmd 515 | run: | 516 | cd ../boost-root/libs/%LIBRARY%/test/cmake_subdir_test/__build__ 517 | cmake --build . --config Release 518 | ctest --output-on-failure --no-tests=error -C Release 519 | 520 | windows-cmake-install: 521 | strategy: 522 | fail-fast: false 523 | matrix: 524 | include: 525 | - os: windows-2019 526 | - os: windows-2022 527 | 528 | runs-on: ${{matrix.os}} 529 | 530 | steps: 531 | - uses: actions/checkout@v4 532 | 533 | - name: Setup Boost 534 | shell: cmd 535 | run: | 536 | echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% 537 | for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi 538 | echo LIBRARY: %LIBRARY% 539 | echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% 540 | echo GITHUB_BASE_REF: %GITHUB_BASE_REF% 541 | echo GITHUB_REF: %GITHUB_REF% 542 | if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% 543 | set BOOST_BRANCH=develop 544 | for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master 545 | echo BOOST_BRANCH: %BOOST_BRANCH% 546 | cd .. 547 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 548 | cd boost-root 549 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ 550 | git submodule update --init tools/boostdep 551 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% 552 | 553 | - name: Configure 554 | shell: cmd 555 | run: | 556 | cd ../boost-root 557 | mkdir __build__ && cd __build__ 558 | cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. 559 | 560 | - name: Install (Debug) 561 | shell: cmd 562 | run: | 563 | cd ../boost-root/__build__ 564 | cmake --build . --target install --config Debug 565 | 566 | - name: Install (Release) 567 | shell: cmd 568 | run: | 569 | cd ../boost-root/__build__ 570 | cmake --build . --target install --config Release 571 | 572 | - name: Use the installed library (Debug) 573 | shell: cmd 574 | run: | 575 | cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test && mkdir __build__ && cd __build__ 576 | cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. 577 | cmake --build . --config Debug 578 | ctest --output-on-failure --no-tests=error -C Debug 579 | 580 | - name: Use the installed library (Release) 581 | shell: cmd 582 | run: | 583 | cd ../boost-root/libs/%LIBRARY%/test/cmake_install_test/__build__ 584 | cmake --build . --config Release 585 | ctest --output-on-failure --no-tests=error -C Release 586 | 587 | windows-cmake-test: 588 | strategy: 589 | fail-fast: false 590 | matrix: 591 | include: 592 | - os: windows-2019 593 | - os: windows-2022 594 | 595 | runs-on: ${{matrix.os}} 596 | 597 | steps: 598 | - uses: actions/checkout@v4 599 | 600 | - name: Setup Boost 601 | shell: cmd 602 | run: | 603 | echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY% 604 | for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi 605 | echo LIBRARY: %LIBRARY% 606 | echo LIBRARY=%LIBRARY%>>%GITHUB_ENV% 607 | echo GITHUB_BASE_REF: %GITHUB_BASE_REF% 608 | echo GITHUB_REF: %GITHUB_REF% 609 | if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF% 610 | set BOOST_BRANCH=develop 611 | for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master 612 | echo BOOST_BRANCH: %BOOST_BRANCH% 613 | cd .. 614 | git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 615 | cd boost-root 616 | xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\ 617 | git submodule update --init tools/boostdep 618 | python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY% 619 | 620 | - name: Configure 621 | shell: cmd 622 | run: | 623 | cd ../boost-root 624 | mkdir __build__ && cd __build__ 625 | cmake -DBOOST_INCLUDE_LIBRARIES=%LIBRARY% -DBUILD_TESTING=ON .. 626 | 627 | - name: Build tests (Debug) 628 | shell: cmd 629 | run: | 630 | cd ../boost-root/__build__ 631 | cmake --build . --target tests --config Debug 632 | 633 | - name: Run tests (Debug) 634 | shell: cmd 635 | run: | 636 | cd ../boost-root/__build__ 637 | ctest --output-on-failure --no-tests=error -C Debug 638 | 639 | - name: Build tests (Release) 640 | shell: cmd 641 | run: | 642 | cd ../boost-root/__build__ 643 | cmake --build . --target tests --config Release 644 | 645 | - name: Run tests (Release) 646 | shell: cmd 647 | run: | 648 | cd ../boost-root/__build__ 649 | ctest --output-on-failure --no-tests=error -C Release 650 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016-2020 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | 5 | language: cpp 6 | 7 | branches: 8 | only: 9 | - master 10 | - develop 11 | - /feature\/.*/ 12 | 13 | env: 14 | matrix: 15 | - BOGUS_JOB=true 16 | 17 | matrix: 18 | 19 | exclude: 20 | - env: BOGUS_JOB=true 21 | 22 | include: 23 | - os: linux 24 | compiler: g++ 25 | env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11 26 | 27 | - os: linux 28 | compiler: g++-4.4 29 | env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98,0x 30 | addons: 31 | apt: 32 | packages: 33 | - g++-4.4 34 | sources: 35 | - ubuntu-toolchain-r-test 36 | 37 | - os: linux 38 | compiler: g++-4.6 39 | env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03,0x 40 | addons: 41 | apt: 42 | packages: 43 | - g++-4.6 44 | sources: 45 | - ubuntu-toolchain-r-test 46 | 47 | - os: linux 48 | compiler: g++-4.7 49 | env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=03,11 50 | addons: 51 | apt: 52 | packages: 53 | - g++-4.7 54 | sources: 55 | - ubuntu-toolchain-r-test 56 | 57 | - os: linux 58 | compiler: g++-4.8 59 | env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=03,11 60 | addons: 61 | apt: 62 | packages: 63 | - g++-4.8 64 | sources: 65 | - ubuntu-toolchain-r-test 66 | 67 | - os: linux 68 | compiler: g++-4.9 69 | env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=03,11 70 | addons: 71 | apt: 72 | packages: 73 | - g++-4.9 74 | sources: 75 | - ubuntu-toolchain-r-test 76 | 77 | - os: linux 78 | compiler: g++-5 79 | env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=03,11,14,1z 80 | addons: 81 | apt: 82 | packages: 83 | - g++-5 84 | sources: 85 | - ubuntu-toolchain-r-test 86 | 87 | - os: linux 88 | compiler: g++-6 89 | env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=03,11,14,1z 90 | addons: 91 | apt: 92 | packages: 93 | - g++-6 94 | sources: 95 | - ubuntu-toolchain-r-test 96 | 97 | - os: linux 98 | compiler: g++-7 99 | env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11,14,17 100 | addons: 101 | apt: 102 | packages: 103 | - g++-7 104 | sources: 105 | - ubuntu-toolchain-r-test 106 | 107 | - os: linux 108 | compiler: g++-8 109 | env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17,2a 110 | addons: 111 | apt: 112 | packages: 113 | - g++-8 114 | sources: 115 | - ubuntu-toolchain-r-test 116 | 117 | - os: linux 118 | compiler: g++-9 119 | env: TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14,17,2a 120 | addons: 121 | apt: 122 | packages: 123 | - g++-9 124 | sources: 125 | - ubuntu-toolchain-r-test 126 | 127 | - os: linux 128 | dist: bionic 129 | compiler: g++-10 130 | env: UBSAN=1 TOOLSET=gcc COMPILER=g++-10 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold 131 | addons: 132 | apt: 133 | packages: 134 | - g++-10 135 | sources: 136 | - ubuntu-toolchain-r-test 137 | 138 | - os: linux 139 | compiler: clang++ 140 | env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11 141 | 142 | - os: linux 143 | dist: trusty 144 | compiler: /usr/bin/clang++ 145 | env: COMMENT=clang-3.3 TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11 146 | addons: 147 | apt: 148 | packages: 149 | - clang-3.3 150 | 151 | - os: linux 152 | dist: trusty 153 | compiler: /usr/bin/clang++ 154 | env: COMMENT=clang-3.4 TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11 155 | addons: 156 | apt: 157 | packages: 158 | - clang-3.4 159 | 160 | - os: linux 161 | compiler: clang++-3.5 162 | env: TOOLSET=clang COMPILER=clang++-3.5 CXXSTD=03,11,14,1z 163 | addons: 164 | apt: 165 | packages: 166 | - clang-3.5 167 | sources: 168 | - ubuntu-toolchain-r-test 169 | 170 | - os: linux 171 | compiler: clang++-3.6 172 | env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=03,11,14,1z 173 | addons: 174 | apt: 175 | packages: 176 | - clang-3.6 177 | sources: 178 | - ubuntu-toolchain-r-test 179 | 180 | - os: linux 181 | compiler: clang++-3.7 182 | env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=03,11,14,1z 183 | addons: 184 | apt: 185 | packages: 186 | - clang-3.7 187 | sources: 188 | - ubuntu-toolchain-r-test 189 | 190 | - os: linux 191 | compiler: clang++-3.8 192 | env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=03,11,14,1z 193 | addons: 194 | apt: 195 | packages: 196 | - clang-3.8 197 | sources: 198 | - ubuntu-toolchain-r-test 199 | 200 | - os: linux 201 | compiler: clang++-3.9 202 | env: TOOLSET=clang COMPILER=clang++-3.9 CXXSTD=03,11,14,1z 203 | addons: 204 | apt: 205 | packages: 206 | - clang-3.9 207 | sources: 208 | - ubuntu-toolchain-r-test 209 | 210 | - os: linux 211 | compiler: clang++-4.0 212 | env: TOOLSET=clang COMPILER=clang++-4.0 CXXSTD=03,11,14,1z 213 | addons: 214 | apt: 215 | packages: 216 | - clang-4.0 217 | sources: 218 | - ubuntu-toolchain-r-test 219 | 220 | - os: linux 221 | compiler: clang++-5.0 222 | env: TOOLSET=clang COMPILER=clang++-5.0 CXXSTD=03,11,14,1z 223 | addons: 224 | apt: 225 | packages: 226 | - clang-5.0 227 | sources: 228 | - ubuntu-toolchain-r-test 229 | 230 | - os: linux 231 | compiler: clang++-6.0 232 | env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17 233 | addons: 234 | apt: 235 | packages: 236 | - clang-6.0 237 | sources: 238 | - ubuntu-toolchain-r-test 239 | 240 | - os: linux 241 | compiler: clang++-7 242 | env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a 243 | addons: 244 | apt: 245 | packages: 246 | - clang-7 247 | sources: 248 | - ubuntu-toolchain-r-test 249 | - llvm-toolchain-xenial-7 250 | 251 | - os: linux 252 | compiler: clang++-8 253 | env: TOOLSET=clang COMPILER=clang++-8 CXXSTD=03,11,14,17,2a 254 | addons: 255 | apt: 256 | packages: 257 | - clang-8 258 | sources: 259 | - ubuntu-toolchain-r-test 260 | - llvm-toolchain-xenial-8 261 | 262 | - os: linux 263 | dist: xenial 264 | compiler: clang++-9 265 | env: TOOLSET=clang COMPILER=clang++-9 CXXSTD=03,11,14,17,2a 266 | addons: 267 | apt: 268 | packages: 269 | - clang-9 270 | sources: 271 | - ubuntu-toolchain-r-test 272 | - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main' 273 | key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' 274 | 275 | - os: linux 276 | dist: xenial 277 | compiler: clang++-10 278 | env: TOOLSET=clang COMPILER=clang++-10 CXXSTD=03,11,14,17,2a 279 | addons: 280 | apt: 281 | packages: 282 | - clang-10 283 | sources: 284 | - ubuntu-toolchain-r-test 285 | - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-10 main' 286 | key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' 287 | 288 | - os: linux 289 | dist: xenial 290 | compiler: clang++-11 291 | env: UBSAN=1 TOOLSET=clang COMPILER=clang++-11 CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 292 | addons: 293 | apt: 294 | packages: 295 | - clang-11 296 | sources: 297 | - ubuntu-toolchain-r-test 298 | - sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-11 main' 299 | key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' 300 | 301 | - os: linux 302 | dist: trusty 303 | compiler: clang++-libc++ 304 | env: TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,1z 305 | addons: 306 | apt: 307 | packages: 308 | - libc++-dev 309 | 310 | - os: linux 311 | dist: bionic 312 | compiler: clang++-libc++ 313 | env: UBSAN=1 TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1 314 | addons: 315 | apt: 316 | packages: 317 | - libc++-dev 318 | 319 | - os: osx 320 | compiler: clang++ 321 | env: UBSAN=1 TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1 322 | 323 | - os: linux 324 | env: CMAKE=1 325 | script: 326 | - mkdir __build__ && cd __build__ 327 | - cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=assert .. 328 | - cmake --build . --target tests 329 | - ctest --output-on-failure 330 | 331 | - os: linux 332 | env: CMAKE_SUBDIR=1 333 | install: 334 | - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true 335 | - git clone -b $BOOST_BRANCH https://github.com/boostorg/config.git ../config 336 | script: 337 | - cd test/cmake_subdir_test && mkdir __build__ && cd __build__ 338 | - cmake .. 339 | - cmake --build . 340 | - cmake --build . --target check 341 | 342 | - os: linux 343 | env: CMAKE_INSTALL=1 344 | script: 345 | - pip install --user cmake 346 | - mkdir __build__ && cd __build__ 347 | - cmake -DBOOST_INCLUDE_LIBRARIES=assert -DCMAKE_INSTALL_PREFIX=~/.local .. 348 | - cmake --build . --target install 349 | - cd ../libs/assert/test/cmake_install_test && mkdir __build__ && cd __build__ 350 | - cmake -DCMAKE_INSTALL_PREFIX=~/.local .. 351 | - cmake --build . 352 | - cmake --build . --target check 353 | 354 | 355 | install: 356 | - BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true 357 | - cd .. 358 | - git clone -b $BOOST_BRANCH https://github.com/boostorg/boost.git boost-root 359 | - cd boost-root 360 | - git submodule update --init tools/build 361 | - git submodule update --init tools/boost_install 362 | - git submodule update --init libs/config 363 | - git submodule update --init libs/core 364 | - git submodule update --init libs/headers 365 | - git submodule update --init tools/cmake 366 | - cp -r $TRAVIS_BUILD_DIR/* libs/assert 367 | - ./bootstrap.sh 368 | - ./b2 headers 369 | 370 | script: 371 | - |- 372 | echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam 373 | - ./b2 libs/assert/test toolset=$TOOLSET cxxstd=$CXXSTD 374 | 375 | notifications: 376 | email: 377 | on_success: always 378 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018-2023 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # https://www.boost.org/LICENSE_1_0.txt 4 | 5 | # We support CMake 3.5, but prefer 3.20 policies and behavior 6 | cmake_minimum_required(VERSION 3.5...3.20) 7 | 8 | project(boost_assert VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX) 9 | 10 | add_library(boost_assert INTERFACE) 11 | add_library(Boost::assert ALIAS boost_assert) 12 | 13 | target_include_directories(boost_assert INTERFACE include) 14 | 15 | target_link_libraries(boost_assert 16 | INTERFACE 17 | Boost::config 18 | ) 19 | 20 | if(CMAKE_VERSION VERSION_GREATER 3.18 AND CMAKE_GENERATOR MATCHES "Visual Studio") 21 | 22 | file(GLOB_RECURSE boost_assert_IDEFILES CONFIGURE_DEPENDS include/*.hpp) 23 | source_group(TREE ${PROJECT_SOURCE_DIR}/include FILES ${boost_assert_IDEFILES} PREFIX "Header Files") 24 | list(APPEND boost_assert_IDEFILES extra/boost_assert.natvis) 25 | target_sources(boost_assert PRIVATE ${boost_assert_IDEFILES}) 26 | 27 | endif() 28 | 29 | # BUILD_TESTING is the standard CTest variable that enables testing 30 | 31 | if(BUILD_TESTING) 32 | 33 | add_subdirectory(test) 34 | 35 | endif() 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Boost.Assert 2 | 3 | The Boost.Assert library, part of the collection of [Boost C++ Libraries](http://github.com/boostorg), 4 | provides several configurable diagnostic macros similar in behavior and purpose to the standard macro 5 | `assert` from ``. 6 | 7 | ## Documentation 8 | 9 | See [the documentation](https://boost.org/libs/assert) for more information. 10 | 11 | ## License 12 | 13 | Distributed under the [Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt). 14 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2016, 2018, 2019 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) 4 | 5 | version: 1.0.{build}-{branch} 6 | 7 | shallow_clone: true 8 | 9 | branches: 10 | only: 11 | - master 12 | - develop 13 | - /feature\/.*/ 14 | 15 | environment: 16 | matrix: 17 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 18 | TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0 19 | ADDRMD: 32 20 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 21 | TOOLSET: msvc-12.0,msvc-14.0 22 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 23 | TOOLSET: msvc-14.1,clang-win 24 | CXXSTD: 14,17,latest 25 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 26 | TOOLSET: msvc-14.0 27 | __CXXFLAGS__: /ZI /FS 28 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 29 | TOOLSET: msvc-14.1 30 | CXXSTD: 14,17,latest 31 | __CXXFLAGS__: /ZI /FS 32 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 33 | TOOLSET: msvc-14.2 34 | CXXSTD: 14,17,20,latest 35 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 36 | ADDPATH: C:\cygwin\bin; 37 | TOOLSET: gcc 38 | CXXSTD: 03,11,14,1z 39 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 40 | ADDPATH: C:\cygwin64\bin; 41 | TOOLSET: gcc 42 | CXXSTD: 03,11,14,1z 43 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 44 | ADDPATH: C:\mingw\bin; 45 | TOOLSET: gcc 46 | CXXSTD: 03,11,14,1z 47 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 48 | ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin; 49 | TOOLSET: gcc 50 | CXXSTD: 03,11,14,1z 51 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 52 | CMAKE: 1 53 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 54 | CMAKE: 1 55 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 56 | CMAKE: 1 57 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 58 | CMAKE_SUBDIR: 1 59 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019 60 | CMAKE_INSTALL: 1 61 | 62 | install: 63 | - set BOOST_BRANCH=develop 64 | - if "%APPVEYOR_REPO_BRANCH%" == "master" set BOOST_BRANCH=master 65 | - cd .. 66 | - git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root 67 | - cd boost-root 68 | - git submodule update --init tools/build 69 | - git submodule update --init tools/boost_install 70 | - git submodule update --init tools/cmake 71 | - git submodule update --init libs/headers 72 | - git submodule update --init libs/config 73 | - git submodule update --init libs/core 74 | - git submodule update --init libs/static_assert 75 | - git submodule update --init libs/throw_exception 76 | - xcopy /s /e /q %APPVEYOR_BUILD_FOLDER% libs\assert\ 77 | - cmd /c bootstrap 78 | - b2 -d0 headers 79 | 80 | build: off 81 | 82 | test_script: 83 | 84 | - PATH=%ADDPATH%%PATH% 85 | - if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD% 86 | - if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD% 87 | - if not "%__CXXFLAGS__%" == "" set __CXXFLAGS__=cxxflags="%__CXXFLAGS__%" 88 | - if "%CMAKE%%CMAKE_SUBDIR%%CMAKE_INSTALL%" == "" b2 -j 1 libs/assert/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% %__CXXFLAGS__% variant=debug,release 89 | 90 | - if not "%CMAKE%" == "" mkdir __build__ && cd __build__ 91 | - if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=assert .. 92 | - if not "%CMAKE%" == "" cmake --build . --target tests --config Debug & ctest --output-on-failure --no-tests=error -C Debug 93 | - if not "%CMAKE%" == "" cmake --build . --target tests --config Release & ctest --output-on-failure --no-tests=error -C Release 94 | - if not "%CMAKE%" == "" cmake --build . --target tests --config MinSizeRel & ctest --output-on-failure --no-tests=error -C MinSizeRel 95 | - if not "%CMAKE%" == "" cmake --build . --target tests --config RelWithDebInfo & ctest --output-on-failure --no-tests=error -C RelWithDebInfo 96 | 97 | - if not "%CMAKE_SUBDIR%" == "" cd libs/assert/test/cmake_subdir_test && mkdir __build__ && cd __build__ 98 | - if not "%CMAKE_SUBDIR%" == "" cmake .. 99 | - if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug 100 | - if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Release && cmake --build . --target check --config Release 101 | - if not "%CMAKE_SUBDIR%" == "" cmake --build . --config MinSizeRel && cmake --build . --target check --config MinSizeRel 102 | - if not "%CMAKE_SUBDIR%" == "" cmake --build . --config RelWithDebInfo && cmake --build . --target check --config RelWithDebInfo 103 | 104 | - if not "%CMAKE_INSTALL%" == "" mkdir __build__ && cd __build__ 105 | - if not "%CMAKE_INSTALL%" == "" cmake -DBOOST_INCLUDE_LIBRARIES=assert -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. 106 | - if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Debug 107 | - if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Release 108 | - if not "%CMAKE_INSTALL%" == "" cd ../libs/assert/test/cmake_install_test && mkdir __build__ && cd __build__ 109 | - if not "%CMAKE_INSTALL%" == "" cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix .. 110 | - if not "%CMAKE_INSTALL%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug 111 | - if not "%CMAKE_INSTALL%" == "" cmake --build . --config Release && cmake --build . --target check --config Release 112 | -------------------------------------------------------------------------------- /build.jam: -------------------------------------------------------------------------------- 1 | # Copyright 2023-2024 René Ferdinand Rivera Morell 2 | # Copyright 2024 Peter Dimov 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # https://www.boost.org/LICENSE_1_0.txt 5 | 6 | require-b2 5.2 ; 7 | 8 | constant boost_dependencies : 9 | /boost/config//boost_config 10 | ; 11 | 12 | project /boost/assert ; 13 | 14 | explicit 15 | [ alias boost_assert : : : : include $(boost_dependencies) ] 16 | [ alias all : boost_assert test ] 17 | ; 18 | 19 | call-if : boost-library assert 20 | ; 21 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | /html/ 2 | /pdf/ 3 | -------------------------------------------------------------------------------- /doc/Jamfile: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Peter Dimov 2 | # 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (See accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | import asciidoctor ; 8 | 9 | html assert.html : index.adoc ; 10 | 11 | install html_ : assert.html : html ; 12 | 13 | pdf assert.pdf : index.adoc ; 14 | explicit assert.pdf ; 15 | 16 | install pdf_ : assert.pdf : pdf ; 17 | explicit pdf_ ; 18 | 19 | ############################################################################### 20 | alias boostdoc ; 21 | explicit boostdoc ; 22 | alias boostrelease : html_ ; 23 | explicit boostrelease ; 24 | -------------------------------------------------------------------------------- /doc/assert.adoc: -------------------------------------------------------------------------------- 1 | //// 2 | Copyright 2002, 2007, 2014, 2017 Peter Dimov 3 | Copyright 2011 Beman Dawes 4 | Copyright 2015 Ion Gaztañaga 5 | 6 | Distributed under the Boost Software License, Version 1.0. 7 | 8 | See accompanying file LICENSE_1_0.txt or copy at 9 | http://www.boost.org/LICENSE_1_0.txt 10 | //// 11 | 12 | [#assertion_macros] 13 | # Assertion Macros, 14 | :toc: 15 | :toc-title: 16 | :idprefix: 17 | 18 | ## BOOST_ASSERT 19 | 20 | The header `` defines the macro `BOOST_ASSERT`, 21 | which is similar to the standard `assert` macro defined in ``. 22 | The macro is intended to be used in both Boost libraries and user 23 | code. 24 | 25 | * By default, `BOOST_ASSERT(expr)` expands to `assert(expr)`. 26 | 27 | * If the macro `BOOST_DISABLE_ASSERTS` is defined when `` 28 | is included, `BOOST_ASSERT(expr)` expands to `((void)0)`, regardless of whether 29 | the macro `NDEBUG` is defined. This allows users to selectively disable `BOOST_ASSERT` without 30 | affecting the definition of the standard `assert`. 31 | 32 | * If the macro `BOOST_ENABLE_ASSERT_HANDLER` is defined when `` 33 | is included, `BOOST_ASSERT(expr)` expands to 34 | + 35 | ```none 36 | (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, 37 | BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 38 | ``` 39 | + 40 | That is, it evaluates `expr` and if it's false, calls 41 | `::boost::assertion_failed(#expr, <>, \\__FILE__, \\__LINE__)`. 42 | This is true regardless of whether `NDEBUG` is defined. 43 | + 44 | `boost::assertion_failed` is declared in `` as 45 | + 46 | ``` 47 | namespace boost 48 | { 49 | #if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) 50 | BOOST_NORETURN 51 | #endif 52 | void assertion_failed(char const * expr, char const * function, 53 | char const * file, long line); 54 | } 55 | ``` 56 | + 57 | but it is never defined. The user is expected to supply an appropriate definition. 58 | 59 | * If the macro `BOOST_ENABLE_ASSERT_DEBUG_HANDLER` is defined when `` 60 | is included, `BOOST_ASSERT(expr)` expands to `((void)0)` when `NDEBUG` is 61 | defined. Otherwise the behavior is as if `BOOST_ENABLE_ASSERT_HANDLER` has been defined. 62 | 63 | As is the case with ``, `` 64 | can be included multiple times in a single translation unit. `BOOST_ASSERT` 65 | will be redefined each time as specified above. 66 | 67 | ## BOOST_ASSERT_MSG 68 | 69 | The macro `BOOST_ASSERT_MSG` is similar to `BOOST_ASSERT`, but it takes an additional argument, 70 | a character literal, supplying an error message. 71 | 72 | * By default, `BOOST_ASSERT_MSG(expr,msg)` expands to `assert\((expr)&&(msg))`. 73 | 74 | * If the macro `BOOST_DISABLE_ASSERTS` is defined when `` 75 | is included, `BOOST_ASSERT_MSG(expr,msg)` expands to `((void)0)`, regardless of whether 76 | the macro `NDEBUG` is defined. 77 | 78 | * If the macro `BOOST_ENABLE_ASSERT_HANDLER` is defined when `` 79 | is included, `BOOST_ASSERT_MSG(expr,msg)` expands to 80 | + 81 | ```none 82 | (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, 83 | msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 84 | ``` 85 | + 86 | This is true regardless of whether `NDEBUG` is defined. 87 | + 88 | `boost::assertion_failed_msg` is declared in `` as 89 | + 90 | ``` 91 | namespace boost 92 | { 93 | #if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) 94 | BOOST_NORETURN 95 | #endif 96 | void assertion_failed_msg(char const * expr, char const * msg, 97 | char const * function, char const * file, long line); 98 | } 99 | ``` 100 | + 101 | but it is never defined. The user is expected to supply an appropriate definition. 102 | 103 | * If the macro `BOOST_ENABLE_ASSERT_DEBUG_HANDLER` is defined when `` 104 | is included, `BOOST_ASSERT_MSG(expr)` expands to `((void)0)` when `NDEBUG` is 105 | defined. Otherwise the behavior is as if `BOOST_ENABLE_ASSERT_HANDLER` has been defined. 106 | 107 | As is the case with ``, `` 108 | can be included multiple times in a single translation unit. `BOOST_ASSERT_MSG` 109 | will be redefined each time as specified above. 110 | 111 | ## BOOST_VERIFY 112 | 113 | The macro `BOOST_VERIFY` has the same behavior as `BOOST_ASSERT`, except that 114 | the expression that is passed to `BOOST_VERIFY` is always 115 | evaluated. This is useful when the asserted expression has desirable side 116 | effects; it can also help suppress warnings about unused variables when the 117 | only use of the variable is inside an assertion. 118 | 119 | * If the macro `BOOST_DISABLE_ASSERTS` is defined when `` 120 | is included, `BOOST_VERIFY(expr)` expands to `\((void)(expr))`. 121 | 122 | * If the macro `BOOST_ENABLE_ASSERT_HANDLER` is defined when `` 123 | is included, `BOOST_VERIFY(expr)` expands to `BOOST_ASSERT(expr)`. 124 | 125 | * Otherwise, `BOOST_VERIFY(expr)` expands to `\((void)(expr))` when `NDEBUG` is 126 | defined, to `BOOST_ASSERT(expr)` when it's not. 127 | 128 | ## BOOST_VERIFY_MSG 129 | 130 | The macro `BOOST_VERIFY_MSG` is similar to `BOOST_VERIFY`, with an additional parameter, an error message. 131 | 132 | * If the macro `BOOST_DISABLE_ASSERTS` is defined when `` 133 | is included, `BOOST_VERIFY_MSG(expr,msg)` expands to `\((void)(expr))`. 134 | 135 | * If the macro `BOOST_ENABLE_ASSERT_HANDLER` is defined when `` 136 | is included, `BOOST_VERIFY_MSG(expr,msg)` expands to `BOOST_ASSERT_MSG(expr,msg)`. 137 | 138 | * Otherwise, `BOOST_VERIFY_MSG(expr,msg)` expands to `\((void)(expr))` when `NDEBUG` is 139 | defined, to `BOOST_ASSERT_MSG(expr,msg)` when it's not. 140 | 141 | ## BOOST_ASSERT_IS_VOID 142 | 143 | The macro `BOOST_ASSERT_IS_VOID` is defined when `BOOST_ASSERT` and `BOOST_ASSERT_MSG` are expanded to `((void)0)`. 144 | Its purpose is to avoid compiling and potentially running code that is only intended to prepare data to be used in the assertion. 145 | 146 | ``` 147 | void MyContainer::erase(iterator i) 148 | { 149 | // Some sanity checks, data must be ordered 150 | #ifndef BOOST_ASSERT_IS_VOID 151 | 152 | if(i != c.begin()) { 153 | iterator prev = i; 154 | --prev; 155 | BOOST_ASSERT(*prev < *i); 156 | } 157 | else if(i != c.end()) { 158 | iterator next = i; 159 | ++next; 160 | BOOST_ASSERT(*i < *next); 161 | } 162 | 163 | #endif 164 | 165 | this->erase_impl(i); 166 | } 167 | ``` 168 | 169 | * By default, `BOOST_ASSERT_IS_VOID` is defined if `NDEBUG` is defined. 170 | * If the macro `BOOST_DISABLE_ASSERTS` is defined, `BOOST_ASSERT_IS_VOID` is always defined. 171 | * If the macro `BOOST_ENABLE_ASSERT_HANDLER` is defined, `BOOST_ASSERT_IS_VOID` is never defined. 172 | * If the macro `BOOST_ENABLE_ASSERT_DEBUG_HANDLER` is defined, then `BOOST_ASSERT_IS_VOID` is defined when `NDEBUG` is defined. 173 | -------------------------------------------------------------------------------- /doc/changes.adoc: -------------------------------------------------------------------------------- 1 | //// 2 | Copyright 2019, 2021 Peter Dimov 3 | Distributed under the Boost Software License, Version 1.0. 4 | http://www.boost.org/LICENSE_1_0.txt 5 | //// 6 | 7 | [#changes] 8 | # Revision History 9 | :toc: 10 | :toc-title: 11 | :idprefix: 12 | 13 | ## Changes in 1.88.0 14 | 15 | * When `BOOST_ASSERT_HANDLER_IS_NORETURN` is defined, `boost::assertion_failed` 16 | and `boost::assertion_failed_msg` are declared as `BOOST_NORETURN`. 17 | 18 | ## Changes in 1.79.0 19 | 20 | * `source_location().file_name()` and `source_location().function_name()` 21 | now return `""` instead of `"(unknown)"`. 22 | * Added a `source_location` constructor from `std::source_location`. 23 | * Changed `BOOST_CURRENT_LOCATION` to more closely match the behavior of 24 | `std::source_location::current()`, such as being usable at top level or 25 | as a default function argument. 26 | 27 | ## Changes in 1.78.0 28 | 29 | * Added `source_location::to_string`. 30 | 31 | ## Changes in 1.73.0 32 | 33 | * Added `source_location`. 34 | -------------------------------------------------------------------------------- /doc/current_function.adoc: -------------------------------------------------------------------------------- 1 | //// 2 | Copyright 2002, 2017 Peter Dimov 3 | 4 | Distributed under the Boost Software License, Version 1.0. 5 | 6 | See accompanying file LICENSE_1_0.txt or copy at 7 | http://www.boost.org/LICENSE_1_0.txt 8 | //// 9 | 10 | [#current_function_macro] 11 | # Current Function Macro, 12 | :toc: 13 | :toc-title: 14 | :idprefix: 15 | 16 | ## BOOST_CURRENT_FUNCTION 17 | 18 | The header `` defines a single macro, `BOOST_CURRENT_FUNCTION`, 19 | similar to the C99 predefined identifier `\\__func__`. 20 | 21 | `BOOST_CURRENT_FUNCTION` expands to either a string literal, or the name of a 22 | character array local to the current function, containing the (fully qualified, 23 | if possible) name of the enclosing function. If there is no enclosing function, 24 | the behavior varies by compiler, but is usually a compile error. 25 | 26 | Some compilers do not provide a way to obtain the name of the current enclosing 27 | function. On such compilers, or when the macro `BOOST_DISABLE_CURRENT_FUNCTION` 28 | is defined, `BOOST_CURRENT_FUNCTION` expands to `"(unknown)"`. 29 | 30 | `BOOST_DISABLE_CURRENT_FUNCTION` addresses a use case in which the programmer 31 | wishes to eliminate the string literals produced by `BOOST_CURRENT_FUNCTION` from 32 | the final executable for security reasons. 33 | -------------------------------------------------------------------------------- /doc/index-docinfo-footer.html: -------------------------------------------------------------------------------- 1 |  7 | -------------------------------------------------------------------------------- /doc/index.adoc: -------------------------------------------------------------------------------- 1 | //// 2 | Copyright 2017 Peter Dimov 3 | 4 | Distributed under the Boost Software License, Version 1.0. 5 | 6 | See accompanying file LICENSE_1_0.txt or copy at 7 | http://www.boost.org/LICENSE_1_0.txt 8 | //// 9 | 10 | # Boost.Assert 11 | Peter Dimov 12 | :toc: left 13 | :idprefix: 14 | :docinfo: private-footer 15 | :source-highlighter: rouge 16 | :source-language: c++ 17 | 18 | The Boost.Assert library provides several configurable diagnostic macros 19 | similar in behavior and purpose to the standard macro `assert` from ``. 20 | 21 | :leveloffset: +1 22 | 23 | include::assert.adoc[] 24 | include::current_function.adoc[] 25 | include::source_location.adoc[] 26 | include::changes.adoc[] 27 | 28 | :leveloffset: -1 29 | 30 | [appendix] 31 | ## Copyright and License 32 | 33 | This documentation is 34 | 35 | * Copyright 2002, 2007, 2014, 2017, 2019-2022 Peter Dimov 36 | * Copyright 2011 Beman Dawes 37 | * Copyright 2015 Ion Gaztañaga 38 | * Distributed under the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0]. 39 | -------------------------------------------------------------------------------- /doc/source_location.adoc: -------------------------------------------------------------------------------- 1 | //// 2 | Copyright 2019, 2021, 2022 Peter Dimov 3 | Distributed under the Boost Software License, Version 1.0. 4 | http://www.boost.org/LICENSE_1_0.txt 5 | //// 6 | 7 | [#source_location_support] 8 | # Source Location Support, 9 | :toc: 10 | :toc-title: 11 | :idprefix: 12 | 13 | ## Description 14 | 15 | The header `` defines `source_location`, 16 | a class representing a source location and containing file, line, function 17 | and column information. It's similar to `std::source_location` from {cpp}20, 18 | but only requires {cpp}03. 19 | 20 | The macro `BOOST_CURRENT_LOCATION` creates a `source_location` object 21 | containing information about the current source location. It can be used 22 | roughly in the same way `std::source_location::current()` can be used, 23 | such as in the declaration of a function default argument: 24 | 25 | ``` 26 | #include 27 | #include 28 | 29 | void f( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) 30 | { 31 | std::cout << "f() called from: " << loc << std::endl; 32 | } 33 | 34 | int main() 35 | { 36 | f(); 37 | } 38 | ``` 39 | 40 | The output of this example varies by compiler and C++ standard level, but 41 | it's generally one of 42 | 43 | ```none 44 | f() called from: example.cpp:11:6 in function 'int main()' 45 | ``` 46 | ```none 47 | f() called from: example.cpp:11:5 in function 'main' 48 | ``` 49 | ```none 50 | f() called from: example.cpp:11 in function 'main' 51 | ``` 52 | ```none 53 | f() called from: example.cpp:4 54 | ``` 55 | 56 | This is useful if, for example, you want to declare a function that throws 57 | an exception, such that the source location of the caller is attached to 58 | the thrown exception: 59 | 60 | ``` 61 | BOOST_NORETURN BOOST_NOINLINE void throw_invalid_argument( 62 | char const* message, 63 | boost::source_location const& loc = BOOST_CURRENT_LOCATION ) 64 | { 65 | boost::throw_exception( std::invalid_argument( message ), loc ); 66 | } 67 | ``` 68 | 69 | Now you could use this helper function in, say, the implementation of 70 | `at` to signal an index that is out of range: 71 | 72 | ``` 73 | T& my_class::at( size_t i ) 74 | { 75 | if( i >= size() ) throw_invalid_argument( "index out of range" ); 76 | return data()[ i ]; 77 | } 78 | ``` 79 | 80 | This would attach the source location of the line in `at` that calls 81 | `throw_invalid_argument` to the thrown exception. 82 | 83 | Note that if instead you use `BOOST_THROW_EXCEPTION` in 84 | `throw_invalid_argument`, the location will be that of 85 | `throw_invalid_argument` and not of its caller. 86 | 87 | ## Synopsis 88 | 89 | ``` 90 | namespace boost 91 | { 92 | 93 | struct source_location 94 | { 95 | constexpr source_location() noexcept; 96 | constexpr source_location( char const* file, uint_least32_t line, 97 | char const* function, uint_least32_t column = 0 ) noexcept; 98 | constexpr source_location( std::source_location const& loc ) noexcept; 99 | 100 | constexpr char const* file_name() const noexcept; 101 | constexpr char const* function_name() const noexcept; 102 | constexpr uint_least32_t line() const noexcept; 103 | constexpr uint_least32_t column() const noexcept; 104 | 105 | std::string to_string() const; 106 | }; 107 | 108 | template 109 | std::basic_ostream & 110 | operator<<( std::basic_ostream & os, source_location const & loc ); 111 | 112 | } // namespace boost 113 | 114 | #define BOOST_CURRENT_LOCATION /* see below */ 115 | ``` 116 | 117 | ## source_location 118 | 119 | ``` 120 | constexpr source_location() noexcept; 121 | ``` 122 | 123 | Effects: :: Constructs a `source_location` object for which `file_name()` 124 | and `function_name()` return `""`, and `line()` and `column()` return `0`. 125 | 126 | ``` 127 | constexpr source_location( char const* file, uint_least32_t line, 128 | char const* function, uint_least32_t column = 0 ) noexcept; 129 | ``` 130 | 131 | Effects: :: Constructs a `source_location` object for which `file_name()` 132 | returns `file`, `function_name()` returns `function`, `line()` returns the 133 | `line` argument and `column()` returns the `column` argument. 134 | 135 | ``` 136 | constexpr source_location( std::source_location const& loc ) noexcept; 137 | ``` 138 | 139 | Effects: :: Constructs a `source_location` object for which `file_name()` 140 | returns `loc.file_name()`, `function_name()` returns `loc.function_name()`, 141 | `line()` returns `loc.line()` and `column()` returns `loc.column()`. 142 | 143 | ## to_string 144 | 145 | ``` 146 | std::string to_string() const; 147 | ``` 148 | 149 | Returns: :: 150 | a string representation of `*this`. 151 | 152 | ## operator<< 153 | 154 | ``` 155 | template 156 | std::basic_ostream & 157 | operator<<( std::basic_ostream & os, source_location const & loc ); 158 | ``` 159 | 160 | Effects: :: `os << loc.to_string()`. 161 | Returns: :: 162 | `os`. 163 | 164 | ## BOOST_CURRENT_LOCATION 165 | 166 | When `BOOST_DISABLE_CURRENT_LOCATION` is defined, the definition of 167 | `BOOST_CURRENT_LOCATION` is: 168 | 169 | ``` 170 | #define BOOST_CURRENT_LOCATION ::boost::source_location() 171 | ``` 172 | 173 | This allows producing executables that contain no identifying information, 174 | for security reasons. 175 | 176 | Otherwise, `BOOST_CURRENT_LOCATION` is defined as the approximate equivalent 177 | of 178 | 179 | ``` 180 | #define BOOST_CURRENT_LOCATION \ 181 | ::boost::source_location(::std::source_location::current()) 182 | ``` 183 | -------------------------------------------------------------------------------- /extra/boost_assert.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {function_,sb} @ {file_,sb}:{line_} 6 | 7 | file_,sb 8 | line_ 9 | column_ 10 | function_,sb 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /include/boost/assert.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // boost/assert.hpp - BOOST_ASSERT(expr) 3 | // BOOST_ASSERT_MSG(expr, msg) 4 | // BOOST_VERIFY(expr) 5 | // BOOST_VERIFY_MSG(expr, msg) 6 | // BOOST_ASSERT_IS_VOID 7 | // 8 | // Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. 9 | // Copyright (c) 2007, 2014 Peter Dimov 10 | // Copyright (c) Beman Dawes 2011 11 | // Copyright (c) 2015 Ion Gaztanaga 12 | // 13 | // Distributed under the Boost Software License, Version 1.0. 14 | // See accompanying file LICENSE_1_0.txt or copy at 15 | // http://www.boost.org/LICENSE_1_0.txt 16 | // 17 | // Note: There are no include guards. This is intentional. 18 | // 19 | // See http://www.boost.org/libs/assert/assert.html for documentation. 20 | // 21 | 22 | // 23 | // Stop inspect complaining about use of 'assert': 24 | // 25 | // boostinspect:naassert_macro 26 | // 27 | 28 | // 29 | // BOOST_ASSERT, BOOST_ASSERT_MSG, BOOST_ASSERT_IS_VOID 30 | // 31 | 32 | #undef BOOST_ASSERT 33 | #undef BOOST_ASSERT_MSG 34 | #undef BOOST_ASSERT_IS_VOID 35 | 36 | #if defined(BOOST_DISABLE_ASSERTS) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && defined(NDEBUG) ) 37 | 38 | # define BOOST_ASSERT(expr) ((void)0) 39 | # define BOOST_ASSERT_MSG(expr, msg) ((void)0) 40 | # define BOOST_ASSERT_IS_VOID 41 | 42 | #elif defined(BOOST_ENABLE_ASSERT_HANDLER) || ( defined(BOOST_ENABLE_ASSERT_DEBUG_HANDLER) && !defined(NDEBUG) ) 43 | 44 | #include // for BOOST_LIKELY 45 | #include 46 | 47 | namespace boost 48 | { 49 | #if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) 50 | BOOST_NORETURN 51 | #endif 52 | void assertion_failed(char const * expr, char const * function, char const * file, long line); // user defined 53 | #if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) 54 | BOOST_NORETURN 55 | #endif 56 | void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line); // user defined 57 | } // namespace boost 58 | 59 | #define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 60 | #define BOOST_ASSERT_MSG(expr, msg) (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 61 | 62 | #else 63 | 64 | # include // .h to support old libraries w/o - effect is the same 65 | 66 | # define BOOST_ASSERT(expr) assert(expr) 67 | # define BOOST_ASSERT_MSG(expr, msg) assert((expr)&&(msg)) 68 | #if defined(NDEBUG) 69 | # define BOOST_ASSERT_IS_VOID 70 | #endif 71 | 72 | #endif 73 | 74 | // 75 | // BOOST_VERIFY, BOOST_VERIFY_MSG 76 | // 77 | 78 | #undef BOOST_VERIFY 79 | #undef BOOST_VERIFY_MSG 80 | 81 | #if defined(BOOST_DISABLE_ASSERTS) || ( !defined(BOOST_ENABLE_ASSERT_HANDLER) && defined(NDEBUG) ) 82 | 83 | # define BOOST_VERIFY(expr) ((void)(expr)) 84 | # define BOOST_VERIFY_MSG(expr, msg) ((void)(expr)) 85 | 86 | #else 87 | 88 | # define BOOST_VERIFY(expr) BOOST_ASSERT(expr) 89 | # define BOOST_VERIFY_MSG(expr, msg) BOOST_ASSERT_MSG(expr,msg) 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /include/boost/assert/source_location.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED 2 | #define BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED 3 | 4 | // http://www.boost.org/libs/assert 5 | // 6 | // Copyright 2019, 2021 Peter Dimov 7 | // Distributed under the Boost Software License, Version 1.0. 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #if !defined(BOOST_NO_IOSTREAM) 17 | #include 18 | #endif 19 | 20 | #if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L 21 | # include 22 | #endif 23 | 24 | namespace boost 25 | { 26 | 27 | struct source_location 28 | { 29 | private: 30 | 31 | char const * file_; 32 | char const * function_; 33 | boost::uint_least32_t line_; 34 | boost::uint_least32_t column_; 35 | 36 | public: 37 | 38 | BOOST_CONSTEXPR source_location() BOOST_NOEXCEPT: file_( "" ), function_( "" ), line_( 0 ), column_( 0 ) 39 | { 40 | } 41 | 42 | BOOST_CONSTEXPR source_location( char const * file, boost::uint_least32_t ln, char const * function, boost::uint_least32_t col = 0 ) BOOST_NOEXCEPT: file_( file ), function_( function ), line_( ln ), column_( col ) 43 | { 44 | } 45 | 46 | #if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L 47 | 48 | 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() ) 49 | { 50 | } 51 | 52 | #endif 53 | 54 | BOOST_CONSTEXPR char const * file_name() const BOOST_NOEXCEPT 55 | { 56 | return file_; 57 | } 58 | 59 | BOOST_CONSTEXPR char const * function_name() const BOOST_NOEXCEPT 60 | { 61 | return function_; 62 | } 63 | 64 | BOOST_CONSTEXPR boost::uint_least32_t line() const BOOST_NOEXCEPT 65 | { 66 | return line_; 67 | } 68 | 69 | BOOST_CONSTEXPR boost::uint_least32_t column() const BOOST_NOEXCEPT 70 | { 71 | return column_; 72 | } 73 | 74 | #if defined(BOOST_MSVC) 75 | # pragma warning( push ) 76 | # pragma warning( disable: 4996 ) 77 | #endif 78 | 79 | #if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) ) 80 | # define BOOST_ASSERT_SNPRINTF(buffer, format, arg) std::sprintf(buffer, format, arg) 81 | #else 82 | # define BOOST_ASSERT_SNPRINTF(buffer, format, arg) std::snprintf(buffer, sizeof(buffer)/sizeof(buffer[0]), format, arg) 83 | #endif 84 | 85 | std::string to_string() const 86 | { 87 | unsigned long ln = line(); 88 | 89 | if( ln == 0 ) 90 | { 91 | return "(unknown source location)"; 92 | } 93 | 94 | std::string r = file_name(); 95 | 96 | char buffer[ 16 ]; 97 | 98 | BOOST_ASSERT_SNPRINTF( buffer, ":%lu", ln ); 99 | r += buffer; 100 | 101 | unsigned long co = column(); 102 | 103 | if( co ) 104 | { 105 | BOOST_ASSERT_SNPRINTF( buffer, ":%lu", co ); 106 | r += buffer; 107 | } 108 | 109 | char const* fn = function_name(); 110 | 111 | if( *fn != 0 ) 112 | { 113 | r += " in function '"; 114 | r += fn; 115 | r += '\''; 116 | } 117 | 118 | return r; 119 | } 120 | 121 | #undef BOOST_ASSERT_SNPRINTF 122 | 123 | #if defined(BOOST_MSVC) 124 | # pragma warning( pop ) 125 | #endif 126 | 127 | inline friend bool operator==( source_location const& s1, source_location const& s2 ) BOOST_NOEXCEPT 128 | { 129 | return std::strcmp( s1.file_, s2.file_ ) == 0 && std::strcmp( s1.function_, s2.function_ ) == 0 && s1.line_ == s2.line_ && s1.column_ == s2.column_; 130 | } 131 | 132 | inline friend bool operator!=( source_location const& s1, source_location const& s2 ) BOOST_NOEXCEPT 133 | { 134 | return !( s1 == s2 ); 135 | } 136 | }; 137 | 138 | #if !defined(BOOST_NO_IOSTREAM) 139 | 140 | template std::basic_ostream & operator<<( std::basic_ostream & os, source_location const & loc ) 141 | { 142 | os << loc.to_string(); 143 | return os; 144 | } 145 | 146 | #endif 147 | 148 | } // namespace boost 149 | 150 | #if defined(BOOST_DISABLE_CURRENT_LOCATION) 151 | 152 | # define BOOST_CURRENT_LOCATION ::boost::source_location() 153 | 154 | #elif defined(BOOST_MSVC) && BOOST_MSVC >= 1935 155 | 156 | # define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCSIG(), __builtin_COLUMN()) 157 | 158 | #elif defined(BOOST_MSVC) && BOOST_MSVC >= 1926 159 | 160 | // std::source_location::current() is available in -std:c++20, but fails with consteval errors before 19.31, and doesn't produce 161 | // the correct result under 19.31, so prefer the built-ins 162 | # define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN()) 163 | 164 | #elif defined(BOOST_MSVC) 165 | 166 | // __LINE__ is not a constant expression under /ZI (edit and continue) for 1925 and before 167 | 168 | # define BOOST_CURRENT_LOCATION_IMPL_1(x) BOOST_CURRENT_LOCATION_IMPL_2(x) 169 | # define BOOST_CURRENT_LOCATION_IMPL_2(x) (x##0 / 10) 170 | 171 | # define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, BOOST_CURRENT_LOCATION_IMPL_1(__LINE__), "") 172 | 173 | #elif defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L && !defined(__NVCC__) 174 | 175 | // Under nvcc, __builtin_source_location is not constexpr 176 | // https://github.com/boostorg/assert/issues/32 177 | 178 | # define BOOST_CURRENT_LOCATION ::boost::source_location(::std::source_location::current()) 179 | 180 | #elif defined(BOOST_CLANG) && BOOST_CLANG_VERSION >= 90000 181 | 182 | # define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION(), __builtin_COLUMN()) 183 | 184 | #elif defined(BOOST_GCC) && BOOST_GCC >= 80000 185 | 186 | // The built-ins are available in 4.8+, but are not constant expressions until 7 187 | // In addition, reproducible builds require -ffile-prefix-map, which is GCC 8 188 | // https://github.com/boostorg/assert/issues/38 189 | 190 | # define BOOST_CURRENT_LOCATION ::boost::source_location(__builtin_FILE(), __builtin_LINE(), __builtin_FUNCTION()) 191 | 192 | #elif defined(BOOST_GCC) && BOOST_GCC >= 50000 193 | 194 | // __PRETTY_FUNCTION__ is allowed outside functions under GCC, but 4.x suffers from codegen bugs 195 | # define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, __PRETTY_FUNCTION__) 196 | 197 | #else 198 | 199 | // __func__ macros aren't allowed outside functions, but BOOST_CURRENT_LOCATION is 200 | # define BOOST_CURRENT_LOCATION ::boost::source_location(__FILE__, __LINE__, "") 201 | 202 | #endif 203 | 204 | #endif // #ifndef BOOST_ASSERT_SOURCE_LOCATION_HPP_INCLUDED 205 | -------------------------------------------------------------------------------- /include/boost/current_function.hpp: -------------------------------------------------------------------------------- 1 | #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED 2 | #define BOOST_CURRENT_FUNCTION_HPP_INCLUDED 3 | 4 | // MS compatible compilers support #pragma once 5 | 6 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 7 | # pragma once 8 | #endif 9 | 10 | // 11 | // boost/current_function.hpp - BOOST_CURRENT_FUNCTION 12 | // 13 | // Copyright 2002-2018 Peter Dimov 14 | // 15 | // Distributed under the Boost Software License, Version 1.0. 16 | // See accompanying file LICENSE_1_0.txt or copy at 17 | // http://www.boost.org/LICENSE_1_0.txt 18 | // 19 | // http://www.boost.org/libs/assert 20 | // 21 | 22 | namespace boost 23 | { 24 | 25 | namespace detail 26 | { 27 | 28 | inline void current_function_helper() 29 | { 30 | 31 | #if defined( BOOST_DISABLE_CURRENT_FUNCTION ) 32 | 33 | # define BOOST_CURRENT_FUNCTION "(unknown)" 34 | 35 | #elif defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__) || defined(__clang__) 36 | 37 | # define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ 38 | 39 | #elif defined(__DMC__) && (__DMC__ >= 0x810) 40 | 41 | # define BOOST_CURRENT_FUNCTION __PRETTY_FUNCTION__ 42 | 43 | #elif defined(__FUNCSIG__) 44 | 45 | # define BOOST_CURRENT_FUNCTION __FUNCSIG__ 46 | 47 | #elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) 48 | 49 | # define BOOST_CURRENT_FUNCTION __FUNCTION__ 50 | 51 | #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) 52 | 53 | # define BOOST_CURRENT_FUNCTION __FUNC__ 54 | 55 | #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) 56 | 57 | # define BOOST_CURRENT_FUNCTION __func__ 58 | 59 | #elif defined(__cplusplus) && (__cplusplus >= 201103) 60 | 61 | # define BOOST_CURRENT_FUNCTION __func__ 62 | 63 | #else 64 | 65 | # define BOOST_CURRENT_FUNCTION "(unknown)" 66 | 67 | #endif 68 | 69 | } 70 | 71 | } // namespace detail 72 | 73 | } // namespace boost 74 | 75 | #endif // #ifndef BOOST_CURRENT_FUNCTION_HPP_INCLUDED 76 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/boostorg/assert/5dcb2af5213ae132b7531e45e7f93258cc33ffd8/index.html -------------------------------------------------------------------------------- /meta/libraries.json: -------------------------------------------------------------------------------- 1 | { 2 | "key": "assert", 3 | "name": "Assert", 4 | "authors": [ 5 | "Peter Dimov" 6 | ], 7 | "maintainers": [ 8 | "Peter Dimov " 9 | ], 10 | "description": "Customizable assert macros.", 11 | "category": [ 12 | "Correctness", 13 | "Error-handling" 14 | ], 15 | "cxxstd": "03" 16 | } 17 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018, 2019 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | include(BoostTestJamfile OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST) 6 | 7 | if(HAVE_BOOST_TEST) 8 | 9 | boost_test_jamfile(FILE Jamfile.v2 LINK_LIBRARIES Boost::assert Boost::core) 10 | 11 | endif() 12 | -------------------------------------------------------------------------------- /test/Jamfile.v2: -------------------------------------------------------------------------------- 1 | # Boost.Assert Library test Jamfile 2 | # 3 | # Copyright (c) 2014, 2017, 2019 Peter Dimov 4 | # 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # See accompanying file LICENSE_1_0.txt or copy at 7 | # http://www.boost.org/LICENSE_1_0.txt 8 | 9 | import testing ; 10 | 11 | project : requirements 12 | /boost/core//boost_core 13 | 14 | extra 15 | msvc:on 16 | clang:on 17 | gcc:on 18 | gcc:-Wshadow 19 | gcc-4.4.7:-Wno-sign-compare 20 | gcc-4.4:-Wno-sign-compare 21 | ; 22 | 23 | run assert_test.cpp ; 24 | run current_function_test.cpp 25 | : : : always_show_run_output ; 26 | run verify_test.cpp ; 27 | run assert_is_void_test.cpp ; 28 | 29 | # expansion tests are in exp/ so that there is a backslash in the path on Windows 30 | run exp/assert_exp_test.cpp ; 31 | run exp/assert_msg_exp_test.cpp ; 32 | run exp/verify_exp_test.cpp ; 33 | run exp/verify_msg_exp_test.cpp ; 34 | run assert_test2.cpp ; 35 | run assert_msg_test2.cpp ; 36 | 37 | # quick test (for CI) 38 | run quick.cpp ; 39 | 40 | run current_function_test2.cpp ; 41 | 42 | run source_location_test.cpp ; 43 | run source_location_test2.cpp ; 44 | run source_location_test3.cpp ; 45 | run source_location_test4.cpp ; 46 | run source_location_test5.cpp ; 47 | run source_location_test6.cpp ; 48 | -------------------------------------------------------------------------------- /test/assert_is_void_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // assert_is_void_test.cpp - tests BOOST_ASSERT_IS_VOID 3 | // 4 | // Copyright (c) 2015 Ion Gaztanaga 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | // 10 | 11 | #include 12 | 13 | // default case, !NDEBUG 14 | // BOOST_ASSERT(x) -> assert(x) 15 | 16 | #undef NDEBUG 17 | #include 18 | 19 | #ifdef BOOST_ASSERT_IS_VOID 20 | #error "BOOST_ASSERT should NOT be void if NDEBUG is not defined" 21 | #endif 22 | 23 | // default case, NDEBUG 24 | // BOOST_ASSERT(x) -> assert(x) 25 | 26 | #define NDEBUG 27 | #include 28 | 29 | #ifndef BOOST_ASSERT_IS_VOID 30 | #error "Error: BOOST_ASSERT should be void in NDEBUG" 31 | #endif 32 | 33 | // BOOST_DISABLE_ASSERTS, !NDEBUG 34 | // BOOST_ASSERT(x) -> ((void)0) 35 | 36 | #define BOOST_DISABLE_ASSERTS 37 | 38 | #undef NDEBUG 39 | #include 40 | 41 | #ifndef BOOST_ASSERT_IS_VOID 42 | #error "Error: BOOST_ASSERT should be void with BOOST_DISABLE_ASSERTS" 43 | #endif 44 | 45 | // BOOST_DISABLE_ASSERTS, NDEBUG 46 | // BOOST_ASSERT(x) -> ((void)0) 47 | 48 | #define NDEBUG 49 | #include 50 | 51 | #ifndef BOOST_ASSERT_IS_VOID 52 | #error "Error: BOOST_ASSERT should be void with BOOST_DISABLE_ASSERTS and NDEBUG" 53 | #endif 54 | 55 | #undef BOOST_DISABLE_ASSERTS 56 | 57 | // BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG 58 | // BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 59 | 60 | #define BOOST_ENABLE_ASSERT_HANDLER 61 | 62 | #undef NDEBUG 63 | #include 64 | 65 | #ifdef BOOST_ASSERT_IS_VOID 66 | #error "Error: BOOST_ASSERT should NOT be void with BOOST_ENABLE_ASSERT_HANDLER" 67 | #endif 68 | 69 | // BOOST_ENABLE_ASSERT_HANDLER, NDEBUG 70 | // BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 71 | 72 | #define NDEBUG 73 | #include 74 | 75 | #ifdef BOOST_ASSERT_IS_VOID 76 | #error "Error: BOOST_ASSERT should NOT be void with BOOST_ENABLE_ASSERT_HANDLER" 77 | #endif 78 | 79 | #undef BOOST_ENABLE_ASSERT_HANDLER 80 | 81 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG 82 | // same as BOOST_ENABLE_ASSERT_HANDLER 83 | 84 | #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER 85 | 86 | #undef NDEBUG 87 | #include 88 | 89 | #ifdef BOOST_ASSERT_IS_VOID 90 | #error "Error: BOOST_ASSERT should NOT be void with BOOST_ENABLE_ASSERT_DEBUG_HANDLER and !NDEBUG" 91 | #endif 92 | 93 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG 94 | // BOOST_ASSERT(x) -> ((void)0) 95 | 96 | #define NDEBUG 97 | #include 98 | 99 | #ifndef BOOST_ASSERT_IS_VOID 100 | #error "Error: BOOST_ASSERT should be void with BOOST_ENABLE_ASSERT_DEBUG_HANDLER and NDEBUG" 101 | #endif 102 | 103 | #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER 104 | 105 | int main() 106 | { 107 | return 0; 108 | } 109 | -------------------------------------------------------------------------------- /test/assert_msg_test2.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // assert_msg_test2.cpp - a test for BOOST_ASSERT_MSG and NDEBUG 3 | // 4 | // Copyright (c) 2014 Peter Dimov 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | // 10 | 11 | #include 12 | #include 13 | 14 | // default case, !NDEBUG 15 | // BOOST_ASSERT_MSG(x) -> assert(x) 16 | 17 | #undef NDEBUG 18 | #include 19 | 20 | void test_default() 21 | { 22 | int x = 1; 23 | 24 | BOOST_ASSERT_MSG( 1, "msg" ); 25 | BOOST_ASSERT_MSG( x, "msg" ); 26 | BOOST_ASSERT_MSG( x == 1, "msg" ); 27 | } 28 | 29 | // default case, NDEBUG 30 | // BOOST_ASSERT_MSG(x) -> assert(x) 31 | 32 | #define NDEBUG 33 | #include 34 | 35 | void test_default_ndebug() 36 | { 37 | int x = 1; 38 | 39 | BOOST_ASSERT_MSG( 1, "msg" ); 40 | BOOST_ASSERT_MSG( x, "msg" ); 41 | BOOST_ASSERT_MSG( x == 1, "msg" ); 42 | 43 | BOOST_ASSERT_MSG( 0, "msg" ); 44 | BOOST_ASSERT_MSG( !x, "msg" ); 45 | BOOST_ASSERT_MSG( x == 0, "msg" ); 46 | 47 | (void)x; 48 | } 49 | 50 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG 51 | // same as BOOST_ENABLE_ASSERT_HANDLER 52 | 53 | #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER 54 | 55 | #undef NDEBUG 56 | #include 57 | 58 | int handler_invoked = 0; 59 | 60 | void boost::assertion_failed_msg( char const * expr, char const * msg, char const * function, char const * file, long line ) 61 | { 62 | printf( "Expression: %s\nMessage: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, msg, function, file, line ); 63 | ++handler_invoked; 64 | } 65 | 66 | void test_debug_handler() 67 | { 68 | handler_invoked = 0; 69 | 70 | int x = 1; 71 | 72 | BOOST_ASSERT_MSG( 1, "msg" ); 73 | BOOST_ASSERT_MSG( x, "msg" ); 74 | BOOST_ASSERT_MSG( x == 1, "msg" ); 75 | 76 | BOOST_ASSERT_MSG( 0, "msg" ); 77 | BOOST_ASSERT_MSG( !x, "msg" ); 78 | BOOST_ASSERT_MSG( x == 0, "msg" ); 79 | 80 | BOOST_TEST( handler_invoked == 3 ); 81 | } 82 | 83 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG 84 | // BOOST_ASSERT_MSG(x) -> ((void)0) 85 | 86 | #define NDEBUG 87 | #include 88 | 89 | void test_debug_handler_ndebug() 90 | { 91 | handler_invoked = 0; 92 | 93 | int x = 1; 94 | 95 | BOOST_ASSERT_MSG( 1, "msg" ); 96 | BOOST_ASSERT_MSG( x, "msg" ); 97 | BOOST_ASSERT_MSG( x == 1, "msg" ); 98 | 99 | BOOST_ASSERT_MSG( 0, "msg" ); 100 | BOOST_ASSERT_MSG( !x, "msg" ); 101 | BOOST_ASSERT_MSG( x == 0, "msg" ); 102 | 103 | BOOST_TEST( handler_invoked == 0 ); 104 | 105 | (void)x; 106 | } 107 | 108 | #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER 109 | 110 | int main() 111 | { 112 | test_default(); 113 | test_default_ndebug(); 114 | test_debug_handler(); 115 | test_debug_handler_ndebug(); 116 | 117 | return boost::report_errors(); 118 | } 119 | -------------------------------------------------------------------------------- /test/assert_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // assert_test.cpp - a test for boost/assert.hpp 3 | // 4 | // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. 5 | // Copyright (c) Beman Dawes 2011 6 | // 7 | // Distributed under the Boost Software License, Version 1.0. (See 8 | // accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | // 11 | 12 | #include 13 | 14 | #if defined(__GNUC__) 15 | # pragma GCC diagnostic ignored "-Waddress" 16 | #endif 17 | 18 | #include 19 | 20 | void test_default() 21 | { 22 | int x = 1; (void)x; 23 | 24 | BOOST_ASSERT(1); 25 | BOOST_ASSERT(x); 26 | BOOST_ASSERT(x == 1); 27 | BOOST_ASSERT(&x); 28 | 29 | BOOST_ASSERT_MSG(1, "msg"); 30 | BOOST_ASSERT_MSG(x, "msg"); 31 | BOOST_ASSERT_MSG(x == 1, "msg"); 32 | BOOST_ASSERT_MSG(&x, "msg"); 33 | } 34 | 35 | #define BOOST_DISABLE_ASSERTS 36 | #include 37 | 38 | void test_disabled() 39 | { 40 | int x = 1; 41 | 42 | BOOST_ASSERT(1); 43 | BOOST_ASSERT(x); 44 | BOOST_ASSERT(x == 1); 45 | BOOST_ASSERT(&x); 46 | 47 | BOOST_ASSERT_MSG(1, "msg"); 48 | BOOST_ASSERT_MSG(x, "msg"); 49 | BOOST_ASSERT_MSG(x == 1, "msg"); 50 | BOOST_ASSERT_MSG(&x, "msg"); 51 | 52 | BOOST_ASSERT(0); 53 | BOOST_ASSERT(!x); 54 | BOOST_ASSERT(x == 0); 55 | 56 | BOOST_ASSERT_MSG(0, "msg"); 57 | BOOST_ASSERT_MSG(!x, "msg"); 58 | BOOST_ASSERT_MSG(x == 0, "msg"); 59 | 60 | void * p = 0; 61 | 62 | BOOST_ASSERT(p); 63 | BOOST_ASSERT_MSG(p, "msg"); 64 | 65 | // suppress warnings 66 | p = &x; 67 | p = &p; 68 | } 69 | 70 | #undef BOOST_DISABLE_ASSERTS 71 | 72 | #define BOOST_ENABLE_ASSERT_HANDLER 73 | #include 74 | #include 75 | #include 76 | 77 | int handler_invoked = 0; 78 | int msg_handler_invoked = 0; 79 | 80 | void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) 81 | { 82 | #if !defined(BOOST_NO_STDC_NAMESPACE) 83 | using std::printf; 84 | #endif 85 | 86 | printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); 87 | ++handler_invoked; 88 | } 89 | 90 | void boost::assertion_failed_msg(char const * expr, char const * msg, char const * function, 91 | char const * file, long line) 92 | { 93 | #if !defined(BOOST_NO_STDC_NAMESPACE) 94 | using std::printf; 95 | #endif 96 | 97 | printf("Expression: %s Message: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", 98 | expr, msg, function, file, line); 99 | ++msg_handler_invoked; 100 | } 101 | 102 | struct X 103 | { 104 | static void f() 105 | { 106 | BOOST_ASSERT(0); 107 | BOOST_ASSERT_MSG(0, "msg f()"); 108 | } 109 | }; 110 | 111 | void test_handler() 112 | { 113 | int x = 1; 114 | 115 | BOOST_ASSERT(1); 116 | BOOST_ASSERT(x); 117 | BOOST_ASSERT(x == 1); 118 | BOOST_ASSERT(&x); 119 | 120 | BOOST_ASSERT_MSG(1, "msg2"); 121 | BOOST_ASSERT_MSG(x, "msg3"); 122 | BOOST_ASSERT_MSG(x == 1, "msg4"); 123 | BOOST_ASSERT_MSG(&x, "msg5"); 124 | 125 | BOOST_ASSERT(0); 126 | BOOST_ASSERT(!x); 127 | BOOST_ASSERT(x == 0); 128 | 129 | BOOST_ASSERT_MSG(0,"msg 0"); 130 | BOOST_ASSERT_MSG(!x, "msg !x"); 131 | BOOST_ASSERT_MSG(x == 0, "msg x == 0"); 132 | 133 | void * p = 0; 134 | 135 | BOOST_ASSERT(p); 136 | BOOST_ASSERT_MSG(p, "msg p"); 137 | 138 | X::f(); 139 | 140 | BOOST_ASSERT(handler_invoked == 5); 141 | BOOST_TEST(handler_invoked == 5); 142 | 143 | BOOST_ASSERT_MSG(msg_handler_invoked == 5, "msg_handler_invoked count is wrong"); 144 | BOOST_TEST(msg_handler_invoked == 5); 145 | } 146 | 147 | #undef BOOST_ENABLE_ASSERT_HANDLER 148 | #undef BOOST_ENABLE_ASSERT_MSG_HANDLER 149 | 150 | int main() 151 | { 152 | test_default(); 153 | test_disabled(); 154 | test_handler(); 155 | 156 | return boost::report_errors(); 157 | } 158 | -------------------------------------------------------------------------------- /test/assert_test2.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // assert_test2.cpp - a test for BOOST_ASSERT and NDEBUG 3 | // 4 | // Copyright (c) 2014 Peter Dimov 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | // 10 | 11 | #include 12 | #include 13 | 14 | // default case, !NDEBUG 15 | // BOOST_ASSERT(x) -> assert(x) 16 | 17 | #undef NDEBUG 18 | #include 19 | 20 | void test_default() 21 | { 22 | int x = 1; 23 | 24 | BOOST_ASSERT( 1 ); 25 | BOOST_ASSERT( x ); 26 | BOOST_ASSERT( x == 1 ); 27 | } 28 | 29 | // default case, NDEBUG 30 | // BOOST_ASSERT(x) -> assert(x) 31 | 32 | #define NDEBUG 33 | #include 34 | 35 | void test_default_ndebug() 36 | { 37 | int x = 1; 38 | 39 | BOOST_ASSERT( 1 ); 40 | BOOST_ASSERT( x ); 41 | BOOST_ASSERT( x == 1 ); 42 | 43 | BOOST_ASSERT( 0 ); 44 | BOOST_ASSERT( !x ); 45 | BOOST_ASSERT( x == 0 ); 46 | 47 | (void)x; 48 | } 49 | 50 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG 51 | // same as BOOST_ENABLE_ASSERT_HANDLER 52 | 53 | #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER 54 | 55 | #undef NDEBUG 56 | #include 57 | 58 | int handler_invoked = 0; 59 | 60 | void boost::assertion_failed( char const * expr, char const * function, char const * file, long line ) 61 | { 62 | printf( "Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line ); 63 | ++handler_invoked; 64 | } 65 | 66 | void test_debug_handler() 67 | { 68 | handler_invoked = 0; 69 | 70 | int x = 1; 71 | 72 | BOOST_ASSERT( 1 ); 73 | BOOST_ASSERT( x ); 74 | BOOST_ASSERT( x == 1 ); 75 | 76 | BOOST_ASSERT( 0 ); 77 | BOOST_ASSERT( !x ); 78 | BOOST_ASSERT( x == 0 ); 79 | 80 | BOOST_TEST( handler_invoked == 3 ); 81 | } 82 | 83 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG 84 | // BOOST_ASSERT(x) -> ((void)0) 85 | 86 | #define NDEBUG 87 | #include 88 | 89 | void test_debug_handler_ndebug() 90 | { 91 | handler_invoked = 0; 92 | 93 | int x = 1; 94 | 95 | BOOST_ASSERT( 1 ); 96 | BOOST_ASSERT( x ); 97 | BOOST_ASSERT( x == 1 ); 98 | 99 | BOOST_ASSERT( 0 ); 100 | BOOST_ASSERT( !x ); 101 | BOOST_ASSERT( x == 0 ); 102 | 103 | BOOST_TEST( handler_invoked == 0 ); 104 | 105 | (void)x; 106 | } 107 | 108 | #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER 109 | 110 | int main() 111 | { 112 | test_default(); 113 | test_default_ndebug(); 114 | test_debug_handler(); 115 | test_debug_handler_ndebug(); 116 | 117 | return boost::report_errors(); 118 | } 119 | -------------------------------------------------------------------------------- /test/check_cmake_version.cpp: -------------------------------------------------------------------------------- 1 | // Check whether the version in CMakeLists.txt is up to date 2 | // 3 | // Copyright 2018 Peter Dimov 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | int main( int ac, char const* av[] ) 15 | { 16 | BOOST_TEST_EQ( ac, 2 ); 17 | 18 | if( ac >= 2 ) 19 | { 20 | char version[ 64 ]; 21 | std::sprintf( version, "%d.%d.%d", BOOST_VERSION / 100000, BOOST_VERSION / 100 % 1000, BOOST_VERSION % 100 ); 22 | 23 | BOOST_TEST_CSTR_EQ( av[1], version ); 24 | } 25 | 26 | return boost::report_errors(); 27 | } 28 | -------------------------------------------------------------------------------- /test/cmake_install_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | cmake_minimum_required(VERSION 3.5...3.16) 6 | 7 | project(cmake_install_test LANGUAGES CXX) 8 | 9 | find_package(boost_assert REQUIRED) 10 | 11 | add_executable(main main.cpp) 12 | target_link_libraries(main Boost::assert) 13 | 14 | enable_testing() 15 | add_test(NAME main COMMAND main) 16 | 17 | add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) 18 | -------------------------------------------------------------------------------- /test/cmake_install_test/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | 7 | int main() 8 | { 9 | int x = 5; 10 | BOOST_ASSERT( x > 4 ); 11 | } 12 | -------------------------------------------------------------------------------- /test/cmake_subdir_test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Peter Dimov 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | cmake_minimum_required(VERSION 3.5...3.16) 6 | 7 | project(cmake_subdir_test LANGUAGES CXX) 8 | 9 | add_subdirectory(../.. boostorg/assert) 10 | add_subdirectory(../../../config boostorg/config) 11 | 12 | add_executable(main main.cpp) 13 | target_link_libraries(main Boost::assert) 14 | 15 | enable_testing() 16 | add_test(NAME main COMMAND main) 17 | 18 | add_custom_target(check VERBATIM COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $) 19 | -------------------------------------------------------------------------------- /test/cmake_subdir_test/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | 7 | int main() 8 | { 9 | int x = 5; 10 | BOOST_ASSERT( x > 4 ); 11 | } 12 | -------------------------------------------------------------------------------- /test/current_function_test.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(BOOST_MSVC) 4 | #pragma warning(disable: 4786) // identifier truncated in debug info 5 | #pragma warning(disable: 4710) // function not inlined 6 | #pragma warning(disable: 4711) // function selected for automatic inline expansion 7 | #pragma warning(disable: 4514) // unreferenced inline removed 8 | #endif 9 | 10 | // 11 | // current_function_test.cpp - a test for boost/current_function.hpp 12 | // 13 | // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. 14 | // 15 | // Distributed under the Boost Software License, Version 1.0. (See 16 | // accompanying file LICENSE_1_0.txt or copy at 17 | // http://www.boost.org/LICENSE_1_0.txt) 18 | // 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | void message(char const * file, long line, char const * func, char const * msg) 25 | { 26 | #if !defined(BOOST_NO_STDC_NAMESPACE) 27 | using std::printf; 28 | #endif 29 | 30 | printf("%s(%ld): in function '%s': %s\n", file, line, func, msg); 31 | } 32 | 33 | #define MESSAGE(msg) message(__FILE__, __LINE__, BOOST_CURRENT_FUNCTION, msg) 34 | 35 | int main() 36 | { 37 | MESSAGE("testing BOOST_CURRENT_FUNCTION"); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /test/current_function_test2.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // current_function_test2.cpp - a test for boost/current_function.hpp 3 | // 4 | // Copyright 2018 Peter Dimov 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | int f() 16 | { 17 | BOOST_TEST_EQ( std::string( BOOST_CURRENT_FUNCTION ).substr( 0, 4 ), std::string( "int " ) ); 18 | return 0; 19 | } 20 | 21 | int main() 22 | { 23 | f(); 24 | return boost::report_errors(); 25 | } 26 | -------------------------------------------------------------------------------- /test/exp/assert_exp_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // assert_exp_test.cpp - tests BOOST_ASSERT expansion 3 | // 4 | // Copyright (c) 2014 Peter Dimov 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // Each backslash in __FILE__ when passed through BOOST_STRINGIZE is doubled 17 | static std::string quote( std::string const & s ) 18 | { 19 | std::string r; 20 | r.reserve( s.size() ); 21 | 22 | for( char const * p = s.c_str(); *p; ++p ) 23 | { 24 | r += *p; 25 | if( *p == '\\' ) r += *p; 26 | } 27 | 28 | return r; 29 | } 30 | 31 | // default case, !NDEBUG 32 | // BOOST_ASSERT(x) -> assert(x) 33 | 34 | #undef NDEBUG 35 | #include 36 | #undef assert 37 | 38 | void test_default() 39 | { 40 | std::string v1 = BOOST_STRINGIZE(BOOST_ASSERT(x1)); 41 | BOOST_TEST_EQ( v1, "assert(x1)" ); 42 | } 43 | 44 | // default case, NDEBUG 45 | // BOOST_ASSERT(x) -> assert(x) 46 | 47 | #define NDEBUG 48 | #include 49 | #undef assert 50 | 51 | void test_default_ndebug() 52 | { 53 | std::string v2 = BOOST_STRINGIZE(BOOST_ASSERT(x2)); 54 | BOOST_TEST_EQ( v2, "assert(x2)" ); 55 | } 56 | 57 | // BOOST_DISABLE_ASSERTS, !NDEBUG 58 | // BOOST_ASSERT(x) -> ((void)0) 59 | 60 | #define BOOST_DISABLE_ASSERTS 61 | 62 | #undef NDEBUG 63 | #include 64 | 65 | void test_disabled() 66 | { 67 | std::string v3 = BOOST_STRINGIZE(BOOST_ASSERT(x3)); 68 | BOOST_TEST_EQ( v3, "((void)0)" ); 69 | } 70 | 71 | // BOOST_DISABLE_ASSERTS, NDEBUG 72 | // BOOST_ASSERT(x) -> ((void)0) 73 | 74 | #define NDEBUG 75 | #include 76 | 77 | void test_disabled_ndebug() 78 | { 79 | std::string v4 = BOOST_STRINGIZE(BOOST_ASSERT(x4)); 80 | BOOST_TEST_EQ( v4, "((void)0)" ); 81 | } 82 | 83 | #undef BOOST_DISABLE_ASSERTS 84 | 85 | // BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG 86 | // BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 87 | 88 | #undef BOOST_LIKELY 89 | #undef BOOST_CURRENT_FUNCTION 90 | 91 | #define BOOST_ENABLE_ASSERT_HANDLER 92 | 93 | #undef NDEBUG 94 | #include 95 | 96 | void test_handler() 97 | { 98 | std::string v5 = BOOST_STRINGIZE(BOOST_ASSERT(x5)); std::string w5 = "(BOOST_LIKELY(!!(x5))? ((void)0): ::boost::assertion_failed(\"x5\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; 99 | 100 | char const * BOOST_CURRENT_FUNCTION = "void test_handler()"; 101 | BOOST_TEST_EQ( v5, w5 ); 102 | } 103 | 104 | // BOOST_ENABLE_ASSERT_HANDLER, NDEBUG 105 | // BOOST_ASSERT(expr) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 106 | 107 | #define NDEBUG 108 | #include 109 | 110 | void test_handler_ndebug() 111 | { 112 | std::string v6 = BOOST_STRINGIZE(BOOST_ASSERT(x6)); std::string w6 = "(BOOST_LIKELY(!!(x6))? ((void)0): ::boost::assertion_failed(\"x6\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; 113 | 114 | char const * BOOST_CURRENT_FUNCTION = "void test_handler_ndebug()"; 115 | BOOST_TEST_EQ( v6, w6 ); 116 | } 117 | 118 | #undef BOOST_ENABLE_ASSERT_HANDLER 119 | 120 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG 121 | // same as BOOST_ENABLE_ASSERT_HANDLER 122 | 123 | #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER 124 | 125 | #undef NDEBUG 126 | #include 127 | 128 | void test_debug_handler() 129 | { 130 | std::string v7 = BOOST_STRINGIZE(BOOST_ASSERT(x7)); std::string w7 = "(BOOST_LIKELY(!!(x7))? ((void)0): ::boost::assertion_failed(\"x7\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; 131 | 132 | char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler()"; 133 | BOOST_TEST_EQ( v7, w7 ); 134 | } 135 | 136 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG 137 | // BOOST_ASSERT(x) -> ((void)0) 138 | 139 | #define NDEBUG 140 | #include 141 | 142 | void test_debug_handler_ndebug() 143 | { 144 | std::string v8 = BOOST_STRINGIZE(BOOST_ASSERT(x8)); 145 | 146 | char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler_ndebug()"; 147 | BOOST_TEST_EQ( v8, "((void)0)" ); 148 | } 149 | 150 | #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER 151 | 152 | int main() 153 | { 154 | test_default(); 155 | test_default_ndebug(); 156 | test_disabled(); 157 | test_disabled_ndebug(); 158 | test_handler(); 159 | test_handler_ndebug(); 160 | test_debug_handler(); 161 | test_debug_handler_ndebug(); 162 | 163 | return boost::report_errors(); 164 | } 165 | -------------------------------------------------------------------------------- /test/exp/assert_msg_exp_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // assert_msg_exp_test.cpp - tests BOOST_ASSERT_MSG expansion 3 | // 4 | // Copyright (c) 2014 Peter Dimov 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // Each backslash in __FILE__ when passed through BOOST_STRINGIZE is doubled 17 | static std::string quote( std::string const & s ) 18 | { 19 | std::string r; 20 | r.reserve( s.size() ); 21 | 22 | for( char const * p = s.c_str(); *p; ++p ) 23 | { 24 | r += *p; 25 | if( *p == '\\' ) r += *p; 26 | } 27 | 28 | return r; 29 | } 30 | 31 | // default case, !NDEBUG 32 | // BOOST_ASSERT_MSG(x,"m") -> assert((x)&&("m")) 33 | 34 | #undef NDEBUG 35 | #include 36 | #undef assert 37 | 38 | void test_default() 39 | { 40 | std::string v1 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x1, "m1")); 41 | BOOST_TEST_EQ( v1, "assert((x1)&&(\"m1\"))" ); 42 | } 43 | 44 | // default case, NDEBUG 45 | // BOOST_ASSERT_MSG(x,"m") -> assert((x)&&("m")) 46 | 47 | #define NDEBUG 48 | #include 49 | #undef assert 50 | 51 | void test_default_ndebug() 52 | { 53 | std::string v2 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x2, "m2")); 54 | BOOST_TEST_EQ( v2, "assert((x2)&&(\"m2\"))" ); 55 | } 56 | 57 | // BOOST_DISABLE_ASSERTS, !NDEBUG 58 | // BOOST_ASSERT_MSG(x,"m") -> ((void)0) 59 | 60 | #define BOOST_DISABLE_ASSERTS 61 | 62 | #undef NDEBUG 63 | #include 64 | 65 | void test_disabled() 66 | { 67 | std::string v3 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x3, "m3")); 68 | BOOST_TEST_EQ( v3, "((void)0)" ); 69 | } 70 | 71 | // BOOST_DISABLE_ASSERTS, NDEBUG 72 | // BOOST_ASSERT_MSG(x,"m") -> ((void)0) 73 | 74 | #define NDEBUG 75 | #include 76 | 77 | void test_disabled_ndebug() 78 | { 79 | std::string v4 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x4, "m4")); 80 | BOOST_TEST_EQ( v4, "((void)0)" ); 81 | } 82 | 83 | #undef BOOST_DISABLE_ASSERTS 84 | 85 | // BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG 86 | // BOOST_ASSERT_MSG(expr, msg) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 87 | 88 | #undef BOOST_LIKELY 89 | #undef BOOST_CURRENT_FUNCTION 90 | 91 | #define BOOST_ENABLE_ASSERT_HANDLER 92 | 93 | #undef NDEBUG 94 | #include 95 | 96 | void test_handler() 97 | { 98 | std::string v5 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x5, "m5")); std::string w5 = "(BOOST_LIKELY(!!(x5))? ((void)0): ::boost::assertion_failed_msg(\"x5\", \"m5\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; 99 | 100 | char const * BOOST_CURRENT_FUNCTION = "void test_handler()"; 101 | BOOST_TEST_EQ( v5, w5 ); 102 | } 103 | 104 | // BOOST_ENABLE_ASSERT_HANDLER, NDEBUG 105 | // BOOST_ASSERT_MSG(expr, msg) -> (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) 106 | 107 | #define NDEBUG 108 | #include 109 | 110 | void test_handler_ndebug() 111 | { 112 | std::string v6 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x6, "m6")); std::string w6 = "(BOOST_LIKELY(!!(x6))? ((void)0): ::boost::assertion_failed_msg(\"x6\", \"m6\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; 113 | 114 | char const * BOOST_CURRENT_FUNCTION = "void test_handler_ndebug()"; 115 | BOOST_TEST_EQ( v6, w6 ); 116 | } 117 | 118 | #undef BOOST_ENABLE_ASSERT_HANDLER 119 | 120 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG 121 | // same as BOOST_ENABLE_ASSERT_HANDLER 122 | 123 | #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER 124 | 125 | #undef NDEBUG 126 | #include 127 | 128 | void test_debug_handler() 129 | { 130 | std::string v7 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x7, "m7")); std::string w7 = "(BOOST_LIKELY(!!(x7))? ((void)0): ::boost::assertion_failed_msg(\"x7\", \"m7\", BOOST_CURRENT_FUNCTION, \"" + quote( __FILE__ ) + "\", " BOOST_STRINGIZE(__LINE__) "))"; 131 | 132 | char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler()"; 133 | BOOST_TEST_EQ( v7, w7 ); 134 | } 135 | 136 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG 137 | // BOOST_ASSERT_MSG(x,"m") -> ((void)0) 138 | 139 | #define NDEBUG 140 | #include 141 | 142 | void test_debug_handler_ndebug() 143 | { 144 | std::string v8 = BOOST_STRINGIZE(BOOST_ASSERT_MSG(x8, "m8")); 145 | 146 | char const * BOOST_CURRENT_FUNCTION = "void test_debug_handler_ndebug()"; 147 | BOOST_TEST_EQ( v8, "((void)0)" ); 148 | } 149 | 150 | #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER 151 | 152 | int main() 153 | { 154 | test_default(); 155 | test_default_ndebug(); 156 | test_disabled(); 157 | test_disabled_ndebug(); 158 | test_handler(); 159 | test_handler_ndebug(); 160 | test_debug_handler(); 161 | test_debug_handler_ndebug(); 162 | 163 | return boost::report_errors(); 164 | } 165 | -------------------------------------------------------------------------------- /test/exp/verify_exp_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // verify_exp_test.cpp - tests BOOST_ASSERT expansion 3 | // 4 | // Copyright (c) 2014 Peter Dimov 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // default case, !NDEBUG 17 | // BOOST_VERIFY(x) -> BOOST_ASSERT(x) 18 | 19 | #undef NDEBUG 20 | #include 21 | #undef BOOST_ASSERT 22 | 23 | void test_default() 24 | { 25 | std::string v1 = BOOST_STRINGIZE(BOOST_VERIFY(x1)); 26 | BOOST_TEST_EQ( v1, "BOOST_ASSERT(x1)" ); 27 | } 28 | 29 | // default case, NDEBUG 30 | // BOOST_VERIFY(x) -> ((void)(x)) 31 | 32 | #define NDEBUG 33 | #include 34 | 35 | void test_default_ndebug() 36 | { 37 | std::string v2 = BOOST_STRINGIZE(BOOST_VERIFY(x2)); 38 | BOOST_TEST_EQ( v2, "((void)(x2))" ); 39 | } 40 | 41 | // BOOST_DISABLE_ASSERTS, !NDEBUG 42 | // BOOST_VERIFY(x) -> ((void)(x)) 43 | 44 | #define BOOST_DISABLE_ASSERTS 45 | #undef NDEBUG 46 | #include 47 | 48 | void test_disabled() 49 | { 50 | std::string v3 = BOOST_STRINGIZE(BOOST_VERIFY(x3)); 51 | BOOST_TEST_EQ( v3, "((void)(x3))" ); 52 | } 53 | 54 | // BOOST_DISABLE_ASSERTS, NDEBUG 55 | // BOOST_VERIFY(x) -> ((void)(x)) 56 | 57 | #undef NDEBUG 58 | #include 59 | 60 | void test_disabled_ndebug() 61 | { 62 | std::string v4 = BOOST_STRINGIZE(BOOST_VERIFY(x4)); 63 | BOOST_TEST_EQ( v4, "((void)(x4))" ); 64 | } 65 | 66 | #undef BOOST_DISABLE_ASSERTS 67 | 68 | // BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG 69 | // BOOST_VERIFY(x) -> BOOST_ASSERT(x) 70 | 71 | #define BOOST_ENABLE_ASSERT_HANDLER 72 | 73 | #undef NDEBUG 74 | #include 75 | #undef BOOST_ASSERT 76 | 77 | void test_handler() 78 | { 79 | std::string v5 = BOOST_STRINGIZE(BOOST_VERIFY(x5)); 80 | BOOST_TEST_EQ( v5, "BOOST_ASSERT(x5)" ); 81 | } 82 | 83 | #define NDEBUG 84 | #include 85 | #undef BOOST_ASSERT 86 | 87 | void test_handler_ndebug() 88 | { 89 | std::string v6 = BOOST_STRINGIZE(BOOST_VERIFY(x6)); 90 | BOOST_TEST_EQ( v6, "BOOST_ASSERT(x6)" ); 91 | } 92 | 93 | #undef BOOST_ENABLE_ASSERT_HANDLER 94 | 95 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG 96 | // BOOST_VERIFY(x) -> BOOST_ASSERT(x) 97 | 98 | #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER 99 | 100 | #undef NDEBUG 101 | #include 102 | #undef BOOST_ASSERT 103 | 104 | void test_debug_handler() 105 | { 106 | std::string v7 = BOOST_STRINGIZE(BOOST_VERIFY(x7)); 107 | BOOST_TEST_EQ( v7, "BOOST_ASSERT(x7)" ); 108 | } 109 | 110 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG 111 | // BOOST_VERIFY(x) -> ((void)(x)) 112 | 113 | #define NDEBUG 114 | #include 115 | 116 | void test_debug_handler_ndebug() 117 | { 118 | std::string v8 = BOOST_STRINGIZE(BOOST_VERIFY(x8)); 119 | BOOST_TEST_EQ( v8, "((void)(x8))" ); 120 | } 121 | 122 | #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER 123 | 124 | int main() 125 | { 126 | test_default(); 127 | test_default_ndebug(); 128 | test_disabled(); 129 | test_disabled_ndebug(); 130 | test_handler(); 131 | test_handler_ndebug(); 132 | test_debug_handler(); 133 | test_debug_handler_ndebug(); 134 | 135 | return boost::report_errors(); 136 | } 137 | -------------------------------------------------------------------------------- /test/exp/verify_msg_exp_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // verify_msg_exp_test.cpp - tests BOOST_VERIFY_MSG expansion 3 | // 4 | // Copyright (c) 2014 Peter Dimov 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // See accompanying file LICENSE_1_0.txt or copy at 8 | // http://www.boost.org/LICENSE_1_0.txt 9 | // 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // default case, !NDEBUG 17 | // BOOST_VERIFY_MSG(x,"m") -> BOOST_ASSERT_MSG(x,"m") 18 | 19 | #undef NDEBUG 20 | #include 21 | #undef BOOST_ASSERT_MSG 22 | 23 | void test_default() 24 | { 25 | std::string v1 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x1, m1)); 26 | BOOST_TEST_EQ( v1, "BOOST_ASSERT_MSG(x1,m1)" ); 27 | } 28 | 29 | // default case, NDEBUG 30 | // BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) 31 | 32 | #define NDEBUG 33 | #include 34 | 35 | void test_default_ndebug() 36 | { 37 | std::string v2 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x2, m2)); 38 | BOOST_TEST_EQ( v2, "((void)(x2))" ); 39 | } 40 | 41 | // BOOST_DISABLE_ASSERTS, !NDEBUG 42 | // BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) 43 | 44 | #define BOOST_DISABLE_ASSERTS 45 | 46 | #undef NDEBUG 47 | #include 48 | 49 | void test_disabled() 50 | { 51 | std::string v3 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x3, "m3")); 52 | BOOST_TEST_EQ( v3, "((void)(x3))" ); 53 | } 54 | 55 | // BOOST_DISABLE_ASSERTS, NDEBUG 56 | // BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) 57 | 58 | #define NDEBUG 59 | #include 60 | 61 | void test_disabled_ndebug() 62 | { 63 | std::string v4 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x4, "m4")); 64 | BOOST_TEST_EQ( v4, "((void)(x4))" ); 65 | } 66 | 67 | #undef BOOST_DISABLE_ASSERTS 68 | 69 | // BOOST_ENABLE_ASSERT_HANDLER, !NDEBUG 70 | // BOOST_VERIFY_MSG(x,m) -> BOOST_ASSERT_MSG(x,m) 71 | 72 | #define BOOST_ENABLE_ASSERT_HANDLER 73 | 74 | #undef NDEBUG 75 | #include 76 | #undef BOOST_ASSERT_MSG 77 | 78 | void test_handler() 79 | { 80 | std::string v5 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x5, m5)); 81 | BOOST_TEST_EQ( v5, "BOOST_ASSERT_MSG(x5,m5)" ); 82 | } 83 | 84 | // BOOST_ENABLE_ASSERT_HANDLER, NDEBUG 85 | // BOOST_VERIFY_MSG(x,n) -> BOOST_ASSERT_MSG(x,m) 86 | 87 | #define NDEBUG 88 | #include 89 | #undef BOOST_ASSERT_MSG 90 | 91 | void test_handler_ndebug() 92 | { 93 | std::string v6 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x6, m6)); 94 | BOOST_TEST_EQ( v6, "BOOST_ASSERT_MSG(x6,m6)" ); 95 | } 96 | 97 | #undef BOOST_ENABLE_ASSERT_HANDLER 98 | 99 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, !NDEBUG 100 | // BOOST_VERIFY_MSG(x,n) -> BOOST_ASSERT_MSG(x,m) 101 | 102 | #define BOOST_ENABLE_ASSERT_DEBUG_HANDLER 103 | 104 | #undef NDEBUG 105 | #include 106 | #undef BOOST_ASSERT_MSG 107 | 108 | void test_debug_handler() 109 | { 110 | std::string v7 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x7, m7)); 111 | BOOST_TEST_EQ( v7, "BOOST_ASSERT_MSG(x7,m7)" ); 112 | } 113 | 114 | // BOOST_ENABLE_ASSERT_DEBUG_HANDLER, NDEBUG 115 | // BOOST_VERIFY_MSG(x,"m") -> ((void)(x)) 116 | 117 | #define NDEBUG 118 | #include 119 | 120 | void test_debug_handler_ndebug() 121 | { 122 | std::string v8 = BOOST_STRINGIZE(BOOST_VERIFY_MSG(x8, "m8")); 123 | BOOST_TEST_EQ( v8, "((void)(x8))" ); 124 | } 125 | 126 | #undef BOOST_ENABLE_ASSERT_DEBUG_HANDLER 127 | 128 | int main() 129 | { 130 | test_default(); 131 | test_default_ndebug(); 132 | test_disabled(); 133 | test_disabled_ndebug(); 134 | test_handler(); 135 | test_handler_ndebug(); 136 | test_debug_handler(); 137 | test_debug_handler_ndebug(); 138 | 139 | return boost::report_errors(); 140 | } 141 | -------------------------------------------------------------------------------- /test/quick.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // quick.cpp - a quick test for boost/assert.hpp 3 | // 4 | // Copyright 2017 Peter Dimov 5 | // 6 | // Distributed under the Boost Software License, Version 1.0. 7 | // 8 | // See accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt 10 | // 11 | 12 | #include 13 | 14 | int main() 15 | { 16 | int x = 1; (void)x; 17 | BOOST_ASSERT( x == 1 ); 18 | } 19 | -------------------------------------------------------------------------------- /test/source_location_test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // http://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | static char const* adjust_filename( char const* file ) 10 | { 11 | #if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20210300 12 | 13 | char const* fn = std::strrchr( file, '/' ); 14 | return fn? fn + 1: file; 15 | 16 | #else 17 | 18 | return file; 19 | 20 | #endif 21 | } 22 | 23 | int main() 24 | { 25 | { 26 | boost::source_location loc; 27 | 28 | BOOST_TEST_CSTR_EQ( loc.file_name(), "" ); 29 | BOOST_TEST_CSTR_EQ( loc.function_name(), "" ); 30 | BOOST_TEST_EQ( loc.line(), 0 ); 31 | BOOST_TEST_EQ( loc.column(), 0 ); 32 | } 33 | 34 | { 35 | boost::source_location loc( __FILE__, __LINE__, "main()" ); 36 | 37 | BOOST_TEST_CSTR_EQ( loc.file_name(), __FILE__ ); 38 | BOOST_TEST_EQ( loc.line(), 35 ); 39 | BOOST_TEST_CSTR_EQ( loc.function_name(), "main()" ); 40 | BOOST_TEST_EQ( loc.column(), 0 ); 41 | } 42 | 43 | { 44 | boost::source_location loc( "file", 1, "main()", 2 ); 45 | 46 | BOOST_TEST_CSTR_EQ( loc.file_name(), "file" ); 47 | BOOST_TEST_EQ( loc.line(), 1 ); 48 | BOOST_TEST_CSTR_EQ( loc.function_name(), "main()" ); 49 | BOOST_TEST_EQ( loc.column(), 2 ); 50 | } 51 | 52 | { 53 | boost::source_location loc = BOOST_CURRENT_LOCATION; 54 | 55 | BOOST_TEST_CSTR_EQ( loc.file_name(), adjust_filename(__FILE__) ); 56 | BOOST_TEST_EQ( loc.line(), 53 ); 57 | } 58 | 59 | { 60 | BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION; 61 | 62 | BOOST_TEST_CSTR_EQ( loc.file_name(), adjust_filename(__FILE__) ); 63 | BOOST_TEST_EQ( loc.line(), 60 ); 64 | } 65 | 66 | #if defined(__cpp_lib_source_location) && __cpp_lib_source_location >= 201907L 67 | 68 | { 69 | std::source_location loc = std::source_location::current(); 70 | boost::source_location loc2 = loc; 71 | 72 | BOOST_TEST_CSTR_EQ( loc2.file_name(), loc.file_name() ); 73 | BOOST_TEST_CSTR_EQ( loc2.function_name(), loc.function_name() ); 74 | BOOST_TEST_EQ( loc2.line(), loc.line() ); 75 | BOOST_TEST_EQ( loc2.column(), loc.column() ); 76 | } 77 | 78 | #endif 79 | 80 | return boost::report_errors(); 81 | } 82 | -------------------------------------------------------------------------------- /test/source_location_test2.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // http://www.boost.org/LICENSE_1_0.txt 4 | 5 | #define BOOST_DISABLE_CURRENT_LOCATION 6 | 7 | #include 8 | #include 9 | 10 | int main() 11 | { 12 | { 13 | boost::source_location loc; 14 | 15 | BOOST_TEST_CSTR_EQ( loc.file_name(), "" ); 16 | BOOST_TEST_CSTR_EQ( loc.function_name(), "" ); 17 | BOOST_TEST_EQ( loc.line(), 0 ); 18 | BOOST_TEST_EQ( loc.column(), 0 ); 19 | } 20 | 21 | { 22 | boost::source_location loc = BOOST_CURRENT_LOCATION; 23 | 24 | BOOST_TEST_CSTR_EQ( loc.file_name(), "" ); 25 | BOOST_TEST_CSTR_EQ( loc.function_name(), "" ); 26 | BOOST_TEST_EQ( loc.line(), 0 ); 27 | BOOST_TEST_EQ( loc.column(), 0 ); 28 | } 29 | 30 | return boost::report_errors(); 31 | } 32 | -------------------------------------------------------------------------------- /test/source_location_test3.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2020, 2021 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // http://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static char const* adjust_filename( char const* file ) 11 | { 12 | #if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20210300 13 | 14 | char const* fn = std::strrchr( file, '/' ); 15 | return fn? fn + 1: file; 16 | 17 | #else 18 | 19 | return file; 20 | 21 | #endif 22 | } 23 | 24 | int main() 25 | { 26 | { 27 | boost::source_location loc; 28 | BOOST_TEST_EQ( loc.to_string(), std::string( "(unknown source location)" ) ); 29 | 30 | std::ostringstream os; 31 | os << loc; 32 | 33 | BOOST_TEST_EQ( os.str(), loc.to_string() ); 34 | } 35 | 36 | { 37 | boost::source_location loc( "file", 5, "" ); 38 | BOOST_TEST_EQ( loc.to_string(), std::string( "file:5" ) ); 39 | 40 | std::ostringstream os; 41 | os << loc; 42 | 43 | BOOST_TEST_EQ( os.str(), loc.to_string() ); 44 | } 45 | 46 | { 47 | boost::source_location loc( "file", 7, "main()" ); 48 | BOOST_TEST_EQ( loc.to_string(), std::string( "file:7 in function 'main()'" ) ); 49 | 50 | std::ostringstream os; 51 | os << loc; 52 | 53 | BOOST_TEST_EQ( os.str(), loc.to_string() ); 54 | } 55 | 56 | { 57 | boost::source_location loc( "file", 11, "main()", 13 ); 58 | BOOST_TEST_EQ( loc.to_string(), std::string( "file:11:13 in function 'main()'" ) ); 59 | 60 | std::ostringstream os; 61 | os << loc; 62 | 63 | BOOST_TEST_EQ( os.str(), loc.to_string() ); 64 | } 65 | 66 | { 67 | boost::source_location loc( "file", 17, "", 19 ); 68 | BOOST_TEST_EQ( loc.to_string(), std::string( "file:17:19" ) ); 69 | 70 | std::ostringstream os; 71 | os << loc; 72 | 73 | BOOST_TEST_EQ( os.str(), loc.to_string() ); 74 | } 75 | 76 | { 77 | boost::source_location loc = BOOST_CURRENT_LOCATION; 78 | 79 | std::string prefix = std::string( adjust_filename(__FILE__) ) + ":77"; 80 | BOOST_TEST_EQ( loc.to_string().substr( 0, prefix.size() ), prefix ); 81 | 82 | std::ostringstream os; 83 | os << loc; 84 | 85 | BOOST_TEST_EQ( os.str(), loc.to_string() ); 86 | } 87 | 88 | return boost::report_errors(); 89 | } 90 | -------------------------------------------------------------------------------- /test/source_location_test4.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // http://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | static char const* adjust_filename( char const* file ) 11 | { 12 | #if defined(__INTEL_LLVM_COMPILER) && __INTEL_LLVM_COMPILER >= 20210300 13 | 14 | char const* fn = std::strrchr( file, '/' ); 15 | return fn? fn + 1: file; 16 | 17 | #else 18 | 19 | return file; 20 | 21 | #endif 22 | } 23 | 24 | boost::source_location s_loc = BOOST_CURRENT_LOCATION; 25 | 26 | BOOST_STATIC_CONSTEXPR boost::source_location c_loc = BOOST_CURRENT_LOCATION; 27 | 28 | boost::source_location f( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) 29 | { 30 | return loc; 31 | } 32 | 33 | int main() 34 | { 35 | { 36 | BOOST_TEST_CSTR_EQ( s_loc.file_name(), adjust_filename(__FILE__) ); 37 | BOOST_TEST_EQ( s_loc.line(), 24 ); 38 | 39 | #if defined(BOOST_GCC) && BOOST_GCC < 90000 40 | // '__static_initialization_and_destruction_0' 41 | #else 42 | BOOST_TEST_CSTR_EQ( s_loc.function_name(), "" ); 43 | #endif 44 | } 45 | 46 | { 47 | BOOST_TEST_CSTR_EQ( c_loc.file_name(), adjust_filename(__FILE__) ); 48 | BOOST_TEST_EQ( c_loc.line(), 26 ); 49 | } 50 | 51 | { 52 | boost::source_location loc = f(); 53 | 54 | BOOST_TEST_CSTR_EQ( loc.file_name(), adjust_filename(__FILE__) ); 55 | BOOST_TEST( loc.line() == 28 || loc.line() == 52 ); 56 | } 57 | 58 | return boost::report_errors(); 59 | } 60 | -------------------------------------------------------------------------------- /test/source_location_test5.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2022 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // http://www.boost.org/LICENSE_1_0.txt 4 | 5 | // Reduced from a boost::system::result test; codegen bug 6 | // in GCC < 5 which is somehow triggered by __PRETTY_FUNCTION__ 7 | // and throwing an exception 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | template class result 14 | { 15 | private: 16 | 17 | bool has_value_; 18 | T value_; 19 | 20 | public: 21 | 22 | result(): has_value_( false ), value_() 23 | { 24 | } 25 | 26 | T value( boost::source_location const& /*loc*/ = BOOST_CURRENT_LOCATION ) const 27 | { 28 | if( has_value_ ) 29 | { 30 | return value_; 31 | } 32 | else 33 | { 34 | throw std::exception(); 35 | } 36 | } 37 | }; 38 | 39 | int main() 40 | { 41 | result r; 42 | BOOST_TEST_THROWS( r.value(), std::exception ); 43 | return boost::report_errors(); 44 | } 45 | -------------------------------------------------------------------------------- /test/source_location_test6.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2019 Peter Dimov 2 | // Distributed under the Boost Software License, Version 1.0. 3 | // http://www.boost.org/LICENSE_1_0.txt 4 | 5 | #include 6 | #include 7 | 8 | int main() 9 | { 10 | { 11 | boost::source_location loc, loc2; 12 | 13 | BOOST_TEST_EQ( loc, loc2 ); 14 | 15 | boost::source_location loc3 = BOOST_CURRENT_LOCATION; 16 | boost::source_location loc4( loc3 ); 17 | 18 | BOOST_TEST_EQ( loc3, loc4 ); 19 | BOOST_TEST_NE( loc3, loc ); 20 | } 21 | 22 | return boost::report_errors(); 23 | } 24 | -------------------------------------------------------------------------------- /test/verify_test.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // verify_test.cpp - a test for BOOST_VERIFY 3 | // 4 | // Copyright (c) 2002 Peter Dimov and Multi Media Ltd. 5 | // Copyright (c) 2007 Peter Dimov 6 | // 7 | // Distributed under the Boost Software License, Version 1.0. (See 8 | // accompanying file LICENSE_1_0.txt or copy at 9 | // http://www.boost.org/LICENSE_1_0.txt) 10 | // 11 | 12 | #include 13 | 14 | #if defined(__GNUC__) 15 | # pragma GCC diagnostic ignored "-Waddress" 16 | #endif 17 | 18 | #include 19 | 20 | int f( int & x ) 21 | { 22 | return ++x; 23 | } 24 | 25 | void test_default() 26 | { 27 | int x = 1; 28 | 29 | BOOST_VERIFY( 1 ); 30 | BOOST_VERIFY( x == 1 ); 31 | BOOST_VERIFY( ++x ); 32 | BOOST_VERIFY( f(x) ); 33 | BOOST_VERIFY( &x ); 34 | 35 | BOOST_TEST( x == 3 ); 36 | } 37 | 38 | #define BOOST_DISABLE_ASSERTS 39 | #include 40 | 41 | void test_disabled() 42 | { 43 | int x = 1; 44 | 45 | BOOST_VERIFY( 1 ); 46 | BOOST_VERIFY( x == 1 ); 47 | BOOST_VERIFY( ++x ); 48 | BOOST_VERIFY( f(x) ); 49 | BOOST_VERIFY( &x ); 50 | 51 | BOOST_TEST( x == 3 ); 52 | 53 | BOOST_VERIFY( 0 ); 54 | BOOST_VERIFY( !x ); 55 | BOOST_VERIFY( x == 0 ); 56 | BOOST_VERIFY( !++x ); 57 | BOOST_VERIFY( !f(x) ); 58 | 59 | BOOST_TEST( x == 5 ); 60 | 61 | void * p = 0; 62 | BOOST_VERIFY( p ); 63 | } 64 | 65 | #undef BOOST_DISABLE_ASSERTS 66 | 67 | #define BOOST_ENABLE_ASSERT_HANDLER 68 | #include 69 | #include 70 | #include 71 | 72 | int handler_invoked = 0; 73 | 74 | void boost::assertion_failed(char const * expr, char const * function, char const * file, long line) 75 | { 76 | #if !defined(BOOST_NO_STDC_NAMESPACE) 77 | using std::printf; 78 | #endif 79 | 80 | printf("Expression: %s\nFunction: %s\nFile: %s\nLine: %ld\n\n", expr, function, file, line); 81 | ++handler_invoked; 82 | } 83 | 84 | struct X 85 | { 86 | static bool f() 87 | { 88 | BOOST_VERIFY( 0 ); 89 | return false; 90 | } 91 | }; 92 | 93 | void test_handler() 94 | { 95 | int x = 1; 96 | 97 | BOOST_VERIFY( 1 ); 98 | BOOST_VERIFY( x == 1 ); 99 | BOOST_VERIFY( ++x ); 100 | BOOST_VERIFY( f(x) ); 101 | BOOST_VERIFY( &x ); 102 | 103 | BOOST_TEST( x == 3 ); 104 | 105 | BOOST_VERIFY( 0 ); 106 | BOOST_VERIFY( !x ); 107 | BOOST_VERIFY( x == 0 ); 108 | BOOST_VERIFY( !++x ); 109 | BOOST_VERIFY( !f(x) ); 110 | 111 | BOOST_TEST( x == 5 ); 112 | 113 | void * p = 0; 114 | BOOST_VERIFY( p ); 115 | 116 | BOOST_VERIFY( X::f() ); 117 | 118 | BOOST_TEST( handler_invoked == 8 ); 119 | } 120 | 121 | #undef BOOST_ENABLE_ASSERT_HANDLER 122 | 123 | int main() 124 | { 125 | test_default(); 126 | test_disabled(); 127 | test_handler(); 128 | 129 | return boost::report_errors(); 130 | } 131 | --------------------------------------------------------------------------------