README.md 835 Bytes
Newer Older
one's avatar
one committed
1
2
# dcc 对 `void` 函数误报 `-Wreturn-type`

3
4
5
6
7
8
9
10
11
12
## 问题描述

DTK26.04 的 `dcc` 编译无返回的 `void` 函数会报错:

```text
void-return.cpp:1:11: error: void function is missing a return statement [-Werror,-Wreturn-type]
void f() {}
          ^
```

one's avatar
one committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## 复现方式

镜像:

```text
harbor.sourcefind.cn:5443/dcu/admin/base/pytorch:2.7.1-ubuntu22.04-dtk26.04-py3.11
```

在容器内执行:

```sh
dcc -std=c++17 -Werror=return-type -c void-return.cpp -o void-return.o
```

## 预期结果

这段源码应该能够正常编译。`void f() {}` 是合法的 C++ 代码,`-Wreturn-type` 不应该仅仅因为 `void` 函数没有显式写出 `return;` 就给出诊断。

当项目启用 `-Werror=return-type` 时,这个问题也会影响更大的构建;普通的空 `void` 函数会在 `dcc` 下变成硬错误。