|
| 1 | +#!/usr/bin/env bash |
| 2 | +# requires: gcc |
| 3 | +# 100_cppfly_reflection.sh — standard = "c++fly" (design 2026-07-14): ONE |
| 4 | +# manifest line gives the toolchain's latest -std= level + every experimental |
| 5 | +# gate it supports. On gcc >= 16 that means -std=c++26 -freflection with zero |
| 6 | +# hand-written flags, reaching every TU, the scan and the std BMI prebuild. |
| 7 | +# Tail section: standard = "c++latest" regression — it used to reach the GNU |
| 8 | +# driver as the invalid spelling -std=c++latest (design §11-Q5). |
| 9 | +set -e |
| 10 | + |
| 11 | +TMP=$(mktemp -d) |
| 12 | +trap "rm -rf $TMP" EXIT |
| 13 | + |
| 14 | +# Capability probe (mirrors 98): newest gcc payload must accept -freflection. |
| 15 | +USER_MCPP="${MCPP_HOME:-$HOME/.mcpp}" |
| 16 | +GXX=$(find "$USER_MCPP/registry/data/xpkgs/xim-x-gcc" -name "g++" -path "*/bin/*" 2>/dev/null | sort | tail -1) |
| 17 | +if [[ -z "$GXX" ]] || ! echo 'int main(){}' | "$GXX" -freflection -std=c++26 -x c++ - -fsyntax-only -o /dev/null 2>/dev/null; then |
| 18 | + echo "SKIP-INLINE: no -freflection-capable gcc payload available" |
| 19 | + exit 0 |
| 20 | +fi |
| 21 | +GCC_VER=$(basename "$(dirname "$(dirname "$GXX")")") |
| 22 | + |
| 23 | +export MCPP_HOME="$TMP/mcpp-home" |
| 24 | +source "$(dirname "$0")/_inherit_toolchain.sh" |
| 25 | + |
| 26 | +mkdir -p "$TMP/proj/src" |
| 27 | +cd "$TMP/proj" |
| 28 | + |
| 29 | +cat > mcpp.toml <<EOF |
| 30 | +[package] |
| 31 | +name = "flydemo" |
| 32 | +version = "0.1.0" |
| 33 | +standard = "c++fly" |
| 34 | +
|
| 35 | +[toolchain] |
| 36 | +default = "gcc@${GCC_VER}" |
| 37 | +EOF |
| 38 | + |
| 39 | +cat > src/main.cpp <<'EOF' |
| 40 | +import std; |
| 41 | +
|
| 42 | +void print_struct(auto &&value) { |
| 43 | + constexpr auto info = std::meta::remove_cvref(^^decltype(value)); |
| 44 | + constexpr auto no_check = std::meta::access_context::unchecked(); |
| 45 | + static constexpr auto members = std::define_static_array( |
| 46 | + std::meta::nonstatic_data_members_of(info, no_check)); |
| 47 | + template for (constexpr auto e : members) { |
| 48 | + auto &&member = value.[:e:]; |
| 49 | + std::println("{} {}", identifier_of(e), member); |
| 50 | + } |
| 51 | +} |
| 52 | +
|
| 53 | +struct Point { double x{}; double y{}; }; |
| 54 | +int main() { |
| 55 | + print_struct(Point{2, 3}); |
| 56 | +} |
| 57 | +EOF |
| 58 | + |
| 59 | +"$MCPP" build --no-cache > "$TMP/build.log" 2>&1 || { |
| 60 | + cat "$TMP/build.log" |
| 61 | + echo "FAIL: c++fly build failed" |
| 62 | + exit 1 |
| 63 | +} |
| 64 | + |
| 65 | +# The c++fly summary: the value's contract is saying what was enabled/skipped. |
| 66 | +grep -q 'c++fly on gcc' "$TMP/build.log" || { |
| 67 | + cat "$TMP/build.log" |
| 68 | + echo "FAIL: build log missing c++fly summary line" |
| 69 | + exit 1 |
| 70 | +} |
| 71 | +grep -q 'reflection (-freflection)' "$TMP/build.log" || { |
| 72 | + cat "$TMP/build.log" |
| 73 | + echo "FAIL: summary missing enabled reflection gate" |
| 74 | + exit 1 |
| 75 | +} |
| 76 | +grep -q 'enabled: .*contracts' "$TMP/build.log" || { |
| 77 | + cat "$TMP/build.log" |
| 78 | + echo "FAIL: summary missing enabled contracts (on by -std=c++26 on gcc16)" |
| 79 | + exit 1 |
| 80 | +} |
| 81 | + |
| 82 | +# Latest level + gate flags reach the global cxxflags (every TU, deps incl.). |
| 83 | +build_ninja="$(find target -name build.ninja | head -1)" |
| 84 | +grep -qE '^cxxflags = -std=c\+\+26 -freflection' "$build_ninja" || { |
| 85 | + grep '^cxxflags' "$build_ninja" || true |
| 86 | + echo "FAIL: build.ninja cxxflags lacks -std=c++26 -freflection" |
| 87 | + exit 1 |
| 88 | +} |
| 89 | +if grep -q -- '-std=c++fly' "$build_ninja" compile_commands.json; then |
| 90 | + echo "FAIL: raw c++fly canonical leaked into a command line" |
| 91 | + exit 1 |
| 92 | +fi |
| 93 | +grep -q '"-freflection"' compile_commands.json || { |
| 94 | + echo "FAIL: compile_commands.json missing -freflection" |
| 95 | + exit 1 |
| 96 | +} |
| 97 | + |
| 98 | +# Reflection actually works at runtime (std::meta over struct members). |
| 99 | +binary=$(find target -type f -path '*/bin/flydemo' | head -1) |
| 100 | +out=$("$binary") |
| 101 | +[[ "$out" == *"x 2"* && "$out" == *"y 3"* ]] || { |
| 102 | + echo "FAIL: reflection output: $out" |
| 103 | + exit 1 |
| 104 | +} |
| 105 | + |
| 106 | +# The std BMI prebuild carries the same dialect (scan/prebuild/compile agree). |
| 107 | +metadata="$(find "$MCPP_HOME/bmi" -name std-module.json | head -1)" |
| 108 | +grep -q '"std_flag": "-std=c++26 -freflection' "$metadata" || { |
| 109 | + cat "$metadata" |
| 110 | + echo "FAIL: std-module.json std_flag lacks -std=c++26 -freflection" |
| 111 | + exit 1 |
| 112 | +} |
| 113 | + |
| 114 | +# ── c++latest regression (design §11-Q5) ──────────────────────────────── |
| 115 | +# Used to emit the invalid GNU spelling -std=c++latest; must now resolve to |
| 116 | +# the family latest level. |
| 117 | +mkdir -p "$TMP/latest/src" |
| 118 | +cd "$TMP/latest" |
| 119 | +cat > mcpp.toml <<EOF |
| 120 | +[package] |
| 121 | +name = "latestdemo" |
| 122 | +version = "0.1.0" |
| 123 | +standard = "c++latest" |
| 124 | +
|
| 125 | +[toolchain] |
| 126 | +default = "gcc@${GCC_VER}" |
| 127 | +EOF |
| 128 | +cat > src/main.cpp <<'EOF' |
| 129 | +import std; |
| 130 | +int main() { std::println("latest ok"); } |
| 131 | +EOF |
| 132 | + |
| 133 | +"$MCPP" build --no-cache > "$TMP/latest-build.log" 2>&1 || { |
| 134 | + cat "$TMP/latest-build.log" |
| 135 | + echo "FAIL: c++latest build failed" |
| 136 | + exit 1 |
| 137 | +} |
| 138 | +latest_ninja="$(find target -name build.ninja | head -1)" |
| 139 | +grep -qE '^cxxflags = -std=c\+\+26' "$latest_ninja" || { |
| 140 | + grep '^cxxflags' "$latest_ninja" || true |
| 141 | + echo "FAIL: c++latest did not resolve to -std=c++26" |
| 142 | + exit 1 |
| 143 | +} |
| 144 | +if grep -q -- '-std=c++latest' "$latest_ninja" compile_commands.json; then |
| 145 | + echo "FAIL: invalid -std=c++latest spelling reached a command line" |
| 146 | + exit 1 |
| 147 | +fi |
| 148 | + |
| 149 | +echo "PASS: c++fly = latest std + experimental gates; c++latest spelling fixed" |
0 commit comments