Silence all compiler warnings in source builds (clang/libc++, Python 3.14) - #141
Conversation
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
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
Done in d7b6f07 — added |
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 implicit1): on libc++ in C++17 mode Boost's ownboost/config/stdlib/libcpp.hppalso definesBOOST_NO_AUTO_PTR(empty), and the differing bodies triggered-Wmacro-redefinedin 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_REFinCMAKE_CXX_FLAGSis 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 viaBOOST_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 theboost/bind.hpppragma message.Scoped warning suppressions for bundled Boost (
src/boost/CMakeLists.txt)boost_pythontarget:-Wno-deprecated-declarations— Boost.Python ≤ 1.87 calls_PyUnicode_AsString, deprecated since Python 3.14. It is a literal alias ofPyUnicode_AsUTF8in CPython's headers, so behavior is unaffected.boosttarget (clang only):-Wno-invalid-noreturn— Boost.MPI'senvironment::abort()is declarednoreturnbut relies onMPI_Abortnot returning, which the compiler cannot verify.Both are
PRIVATEto 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 legacylagged_fibonacci607generator islagged_fibonacci<uint32_t, 48, 607, 273>, a 48-bit word with a 32-bit result type, somax()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 throughmcbase*was undefined behavior.alps::EigenvectorMeasurements(src/alps/scheduler/measurement_operators.h): hasvirtual save/loadbut 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 byCMAKE_CXX_COMPILER_ID MATCHES "Clang"so GCC builds are unaffected.🤖 Generated with Claude Code
https://claude.ai/code/session_01DaRLRTayS75a9Yk1iLvNu9