Case Study: The C++20 Migration Compiled Clean. A 40-Line Property Test Found the Ordering Break.
说明与用途
将库迁移到 C++20 改变了记录的排序顺序,只有通过 40 行属性测试才发现。测试表明,自动 diff 将手写的 operator< 替换为默认的 <=>,改变了成员顺序,从而改变了排序。
问题
Migrating a 2,400‑line library to C++20 changed the sort order of report records, breaking callers that relied on a specific priority‑timestamp‑name ordering.
结果
The property test revealed that the defaulted comparison changed the ordering, exposing a regression that unit tests missed.
工作流
- Snapshot existing test outputs’ SHA‑256
- Prompt model to apply only mechanical changes
- Apply diff and build with -std=c++20 -Wall -Wextra -Werror
- Run existing 14 unit tests
- Add ordering property test
- Run whole job under ASan and UBSan
证据
The model’s reasoning was defensible. A defaulted <= > generates all six comparison operators, and operator< is synthesized from it.
The risky 13% was a single change to Record.
- 记录日期: 2026-09-09T05:15:22.782Z