---
title: 非void函数没有写返回值时的运行行为存在差异
description: "```"
url: https://www.hikunpeng.com/document/detail/zh/kunpengdevps/compilation/ug-bisheng/kunpengbisheng_06_0091.html
sourcePath: /source/zh/kunpengdevps/compilation/ug-bisheng/kunpengbisheng_06_0091.html
indexId: 0aa1be7fc59d6f8dd8edd228ecaaee8bee52d768e51561128659ae9552e8205a74
---
# 非void函数没有写返回值时的运行行为存在差异

#### 错误信息

```
warning: non-void function does not return a value in all control paths [-Wreturn-type]
Trace/breakpoint trap (core dumped)
```


#### 问题介绍

编译器出于二进制安全考虑，会在没有返回值的分支插入非法指令，可能会导致运行时coredump。


#### 解决方案

- 为非void函数添加返回值；
- 将没有返回值的函数类型修改为void；
- 使用clang-tidy工具可以识别该类问题并提供修改建议。
