← 都来码 / Dolaima← 例程索引cpp/test/move_name.cpp 原文

cpp/test/move_name.cpp · 1126 字节 · 下载原文

/* move_name.cpp —— 回归判据:用户函数名里带 `_move` / 叫 `move` 的调用不能被吞掉
 * move_name.cpp -- regression probe: a user function named `move` / `*_move` must still be called
 *
 * 2026-11-15 实测的坑:C++ 前端把「名字含 `_move` 或叫 `move`、且只有一个实参」的调用
 * 一律当成 `std::move(x)` 展开成表达式 —— 用户函数 `move(0)` / `g2048_move(0)` 于是
 * **整条调用被丢弃**:编译通过、运行起来点了没反应(`cpp/app/g2048.cpp` 的按键全是死的)。
 * 导出 VML 能看到 `func_g2048_move_1:` 有标签、**没有任何 call**。
 *
 * 判据:输出必须是 `move_name=42`(38+4)。为 0 说明调用又被当成 std::move 吞了。
 * Criteria: the output must be `move_name=42` (38+4). A 0 means the call was swallowed again.
 */

#include <stdio.h>

static int bump(int v) { return v + 4; }
static int board_move(int v) { return bump(v); }
static int move(int v) { return board_move(v) + 1; }

int main(void)
{
    printf("move_name=%d\n", board_move(38));
    printf("move_plain=%d\n", move(38));
    return 0;
}