Skip to content

Silence all compiler warnings in source builds (clang/libc++, Python 3.14) - #141

Merged
Ooolab merged 2 commits into
masterfrom
fix/silence-build-warnings
Sep 7, 2026
Merged

Ooolab merged 2 commits into
masterfrom
fix/silence-build-warnings

Conversation

@Ooolab

@Ooolab Ooolab commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Building ALPS from source per the install instructions on macOS (AppleClang 17, libc++, macOS SDK 26.2, Homebrew Python 3.14) produced a stream of recurring warnings. This PR removes all of them — a full build including examples and tests now finishes with zero warnings. The bundled/downloaded Boost sources are untouched; everything is done in ALPS's own CMake files and two ALPS headers.

Preprocessor defines (top-level CMakeLists.txt)

  • -DBOOST_NO_AUTO_PTR= (empty value instead of implicit 1): on libc++ in C++17 mode Boost's own boost/config/stdlib/libcpp.hpp also defines BOOST_NO_AUTO_PTR (empty), and the differing bodies triggered -Wmacro-redefined in every translation unit that includes Boost. Identical redefinitions are legal and silent. Side note: since the build adds this flag itself, the install page telling users to pass -DBOOST_NO_AUTO_PTR -DBOOST_FILESYSTEM_NO_CXX20_ATOMIC_REF in CMAKE_CXX_FLAGS is redundant (and reintroduces this warning) — the docs could drop it.
  • -DBOOST_ALLOW_DEPRECATED_HEADERS: Boost's official opt-out for the <boost/timer.hpp> "header is deprecated" pragma message — we already opt into the old timer API via BOOST_TIMER_ENABLE_DEPRECATED.
  • -DBOOST_BIND_GLOBAL_PLACEHOLDERS: Boost's official opt-in for the global _1, _2, ... bind placeholders that legacy ALPS code uses throughout, silencing the boost/bind.hpp pragma message.

Scoped warning suppressions for bundled Boost (src/boost/CMakeLists.txt)

  • boost_python target: -Wno-deprecated-declarations — Boost.Python ≤ 1.87 calls _PyUnicode_AsString, deprecated since Python 3.14. It is a literal alias of PyUnicode_AsUTF8 in CPython's headers, so behavior is unaffected.
  • boost target (clang only): -Wno-invalid-noreturn — Boost.MPI's environment::abort() is declared noreturn but relies on MPI_Abort not returning, which the compiler cannot verify.

Both are PRIVATE to the bundled Boost targets, so ALPS code keeps these warnings enabled.

Scoped suppression for legacy RNG (src/alps/CMakeLists.txt)

  • random/rngfactory.C (clang only): -Wno-constant-conversion — the registered legacy lagged_fibonacci607 generator is lagged_fibonacci<uint32_t, 48, 607, 273>, a 48-bit word with a 32-bit result type, so max() truncates 2^48−1 to 2^32−1 by construction. Changing the types would change the random stream and break reproducibility of old simulations, so the parameterization is kept and the warning suppressed for this one file.

Real fixes: missing virtual destructors

  • alps::mcbase (src/alps/mcbase.hpp): abstract class destroyed through base references by Boost.Python's rvalue converters (-Wdelete-abstract-non-virtual-dtor). Deleting a derived simulation through mcbase* was undefined behavior.
  • alps::EigenvectorMeasurements (src/alps/scheduler/measurement_operators.h): has virtual save/load but had no virtual destructor (-Wdelete-non-abstract-non-virtual-dtor).

Both classes already had vtables, so adding the destructor changes no object layout and no ABI-visible behavior; derived classes' destructors become virtual overrides automatically.

Testing

Full from-source build (cmake --build, including examples and tests) on AppleClang 17 / macOS SDK 26.2 / Homebrew Python 3.14 with the bundled Boost 1.87: previously dozens of warning sites, now zero warnings. The clang-only -Wno-* flags are guarded by CMAKE_CXX_COMPILER_ID MATCHES "Clang" so GCC builds are unaffected.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DaRLRTayS75a9Yk1iLvNu9

Building from source on macOS (AppleClang, libc++, Python 3.14) produced
several recurring warnings. This cleans them all up without touching the
bundled Boost sources:

- Define BOOST_NO_AUTO_PTR with an empty value to match Boost's own
  definition in boost/config/stdlib/libcpp.hpp (identical redefinitions
  are legal and silent; -DBOOST_NO_AUTO_PTR expands to 1 and warned on
  every TU with -Wmacro-redefined).
- Define BOOST_ALLOW_DEPRECATED_HEADERS and BOOST_BIND_GLOBAL_PLACEHOLDERS,
  Boost's official opt-outs for the <boost/timer.hpp> deprecation pragma
  (we already set BOOST_TIMER_ENABLE_DEPRECATED) and the global bind
  placeholders pragma.
- Suppress -Wdeprecated-declarations for the bundled boost_python target
  only: Boost.Python <= 1.87 calls _PyUnicode_AsString, deprecated since
  Python 3.14 (it is an alias of PyUnicode_AsUTF8, so behavior is fine).
- Suppress -Winvalid-noreturn (clang only) for the bundled boost target:
  Boost.MPI's environment::abort() is noreturn but the compiler cannot
  know MPI_Abort does not return.
- Suppress -Wconstant-conversion (clang only) for rngfactory.C: the
  legacy lagged_fibonacci607 generator uses a 48-bit word with a 32-bit
  result type, so max() truncates by design; kept for stream
  compatibility with old simulations.
- Add virtual destructors to alps::mcbase (abstract, destroyed through
  base references by Boost.Python's converters) and
  alps::EigenvectorMeasurements (virtual save/load); fixes
  -Wdelete-abstract-non-virtual-dtor / -Wdelete-non-abstract-non-virtual-dtor
  and closes genuine UB if instances are ever deleted via a base pointer.
  No object layout change since both classes already had vtables.

With these changes a full build (including examples and tests) completes
with zero warnings on AppleClang 17 / macOS SDK 26.2 / Python 3.14.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DaRLRTayS75a9Yk1iLvNu9

@egull egull left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you! We had previous passes to make this compile without warnings on C++-14; it's quite amazing how much more C++-17 finds.

@marcusr2ML marcusr2ML left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not a big deal: with the bundled Boost, one file (libs/filesystem/src/directory.cpp) calls readdir_r, which recent macOS SDKs mark deprecated, so you get a single -Wdeprecated-declarations warning building libboost, it's on master too and harmless. To clear it, add -Wno-deprecated-declarations to the main boost target in src/boost/CMakeLists.txt, right where the PR already adds -Wno-invalid-noreturn to it.

Per review: recent macOS SDKs (and glibc) deprecate readdir_r, which
Boost.Filesystem's directory.cpp still uses, leaving one
-Wdeprecated-declarations warning on the bundled boost target. Scope the
suppression to that target, next to the existing -Wno-invalid-noreturn.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DaRLRTayS75a9Yk1iLvNu9
@Ooolab

Ooolab commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Done in d7b6f07 — added -Wno-deprecated-declarations on the main boost target next to -Wno-invalid-noreturn. Left it outside the clang-only guard since GCC accepts the flag and glibc deprecates readdir_r as well.

@Ooolab
Ooolab merged commit d9a85e7 into master Sep 7, 2026
73 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants