Skip to content

Fix C++ standard probe to match actual build environment (ICU 76+)#204

Open
nielsonrolim wants to merge 1 commit into
brianmario:masterfrom
nielsonrolim:fix-icu77-cxx-standard-detection
Open

Fix C++ standard probe to match actual build environment (ICU 76+)#204
nielsonrolim wants to merge 1 commit into
brianmario:masterfrom
nielsonrolim:fix-icu77-cxx-standard-detection

Conversation

@nielsonrolim

Copy link
Copy Markdown

Summary

Fixes #203charlock_holmes fails to build against ICU 76+ on systems where the compiler's "raw" C++ default is newer than g++ -std=gnu++11.

The C++-standard auto-detect added in e6bf734 probes with try_compile plus -x c++, which on modern GCC (e.g. GCC 15 on Fedora 44) defaults to a C++17+ standard. The real .cpp build, however, uses RbConfig::CONFIG["CXX"], which on most Ruby builds is g++ -std=gnu++11. The probe therefore silently passes while transliterator.cpp still fails with hundreds of errors out of ICU's headers (std::u16string_view, std::enable_if_t, auto non-type template parameters, etc.).

This PR makes the probe represent reality by:

  1. Mirroring the -std= flag baked into CXX into the try_compile invocation, so the probe fails exactly when the real build would fail.
  2. When a working standard is found, appending -std=... to $CXXFLAGS (so it only affects .cpp compilation) instead of $CPPFLAGS (which also leaked -x c++ and -std=c++17 onto the .c compile lines).

A later -std= overrides the one baked into CXX on both gcc and clang, so this cleanly upgrades the standard for ICU's headers without disturbing the rest of the build.

Test plan

Reproduced the failure on the affected environment (Fedora 44, GCC 15, ICU 77.1, Ruby 4.0.3) and verified:

  • Before the fix: checking for icu that requires explicit C++ version flag... no followed by make failing in transliterator.cpp with std::u16string_view, enable_if_t, and auto template parameter errors.
  • After the fix: checking for icu that requires explicit C++ version flag... yeschecking for icu that compiles with c++20 standard... yes, and rake compile test passes (27 runs, 120 assertions, 0 failures, 0 errors).
  • Generated Makefile now has CXXFLAGS = ... -std=c++20 ... (only on the C++ rule) — the .c files no longer get the C++ standard flag.

🤖 Generated with Claude Code

The auto-detect added in e6bf734 used `try_compile` with `gcc -x c++`,
which on modern GCC defaults to a newer C++ standard than the
`-std=gnu++11` that Ruby's RbConfig bakes into `CXX`. On Fedora 44 with
GCC 15 and ICU 77 the probe silently passed while the real .cpp build
still failed with hundreds of errors out of ICU's headers
(`std::u16string_view`, `std::enable_if_t`, `auto` non-type template
parameters, etc.).

Mirror the `-std=` from `CXX` into the probe so it reflects what `.cpp`
files will actually be compiled with, and append the discovered standard
to `$CXXFLAGS` instead of `$CPPFLAGS` so it only applies to C++
sources (a later `-std=` overrides the one baked into `CXX` on
gcc/clang).

Fixes brianmario#203.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

charlock_holmes 0.7.9 fails to build against ICU 77: ICU headers require C++17 but extension compiles with older standard

1 participant