From 99cdcf12e70c0f1d1f8c20ee2e08585f1d1aba68 Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Mon, 6 Jul 2026 14:49:18 -0400 Subject: [PATCH] Add better exclusion tags for pre-processor in examples --- doc/modules/ROOT/pages/examples.adoc | 6 +++--- examples/basic_usage_stacktrace.cpp | 8 ++++++++ examples/fmt_format.cpp | 4 ++++ examples/safety_profile.cpp | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/doc/modules/ROOT/pages/examples.adoc b/doc/modules/ROOT/pages/examples.adoc index d5363b53..bdda0d44 100644 --- a/doc/modules/ROOT/pages/examples.adoc +++ b/doc/modules/ROOT/pages/examples.adoc @@ -33,7 +33,7 @@ Error Detected: Overflow detected in unsigned addition ==== [source, c++] ---- -include::example$basic_usage_stacktrace.cpp[] +include::example$basic_usage_stacktrace.cpp[tags=**;!exclude] ---- Output on Linux x64: @@ -263,7 +263,7 @@ The example approximates the same effect with a type alias so it compiles either ==== [source, c++] ---- -include::example$safety_profile.cpp[] +include::example$safety_profile.cpp[tags=**;!exclude] ---- Output without `BOOST_SAFE_NUMBERS_INTEGER_SAFETY_PROFILE` (silent wrap-around): @@ -342,7 +342,7 @@ IMPORTANT: The header `` is *NOT* part of the ==== [source, c++] ---- -include::example$fmt_format.cpp[] +include::example$fmt_format.cpp[tags=**;!exclude] ---- Output: diff --git a/examples/basic_usage_stacktrace.cpp b/examples/basic_usage_stacktrace.cpp index a8ef4e79..e704b11f 100644 --- a/examples/basic_usage_stacktrace.cpp +++ b/examples/basic_usage_stacktrace.cpp @@ -5,6 +5,7 @@ #include // For safe_numbers types #include // For safe_numbers support #include // For boost::diagnostic_information +// tag::exclude[] #if (defined(__x86_64__) || defined(_M_X64)) && !defined(__MINGW32__) && !defined(__CYGWIN__) @@ -16,10 +17,13 @@ #pragma GCC diagnostic ignored "-Wold-style-cast" #endif +// end::exclude[] #include // For boost::stacktrace::from_current_exception +// tag::exclude[] #endif +// end::exclude[] #include #include @@ -41,7 +45,9 @@ int main() // at the throw site. boost::diagnostic_information extracts all of it. std::cerr << boost::diagnostic_information(e) << std::endl; + // tag::exclude[] #if (defined(__x86_64__) || defined(_M_X64)) && !defined(__MINGW32__) && !defined(__CYGWIN__) + // end::exclude[] // On x86_64, boost::stacktrace can capture the throw-site stacktrace // from the current exception via from_current_exception(). // This requires linking with boost_stacktrace_from_exception. @@ -50,7 +56,9 @@ int main() { std::cerr << "Stacktrace:\n" << st << std::endl; } + // tag::exclude[] #endif + // end::exclude[] } return 0; diff --git a/examples/fmt_format.cpp b/examples/fmt_format.cpp index 620c5d48..41d4701f 100644 --- a/examples/fmt_format.cpp +++ b/examples/fmt_format.cpp @@ -2,10 +2,12 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt +// tag::exclude[] #define FMT_HEADER_ONLY #if __has_include() +// end::exclude[] #include #include #include @@ -62,6 +64,7 @@ int main() return 0; } +// tag::exclude[] #else @@ -73,3 +76,4 @@ int main() } #endif +// end::exclude[] diff --git a/examples/safety_profile.cpp b/examples/safety_profile.cpp index 04bd6d27..60728019 100644 --- a/examples/safety_profile.cpp +++ b/examples/safety_profile.cpp @@ -27,11 +27,13 @@ #include #include #include +// tag::exclude[] #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4127) // Conditional expression is constant #endif +// end::exclude[] #ifdef BOOST_SAFE_NUMBERS_INTEGER_SAFETY_PROFILE using u32 = boost::safe_numbers::u32;