#pragma 处理警告 clang diagnostic 的使用
2024-09-01 17:16:27
首先#pragma在本质上是声明,常用的功能就是注释,尤其是给Code分段注释;而且它还有另一个强大的功能是处理编译器警告,但却没有上一个功能用的那么多。
clang diagnostic 是#pragma 第一个常用命令:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-相关命令"
// 你自己的代码
#pragma clang diagnostic pop
常见的用法
1. 方法弃用告警
1
2
3
4
|
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wincompatible-pointer-types" // #pragma clang diagnostic pop |
2. 不兼容指针类型
1
2
3
4
|
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wincompatible-pointer-types" // #pragma clang diagnostic pop |
3. 循环引用
1
2
3
4
5
6
7
|
// completionBlock is manually nilled out in AFURLConnectionOperation to break the retain cycle. #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-retain-cycles" self.completionBlock = ^ { ... }; #pragma clang diagnostic pop |
4. 未使用变量
1
2
3
4
|
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-variable" int a; #pragma clang diagnostic pop |
5. 未使用default
1
2
3
4
5
6
7
8
9
10
11
12
|
#pragma clang diagnostic push #pragma clang diagnostic ignored "-Wcovered-switch-default" // switch (style) { // case UITableViewCellStyleDefault: // case UITableViewCellStyleValue1: // case UITableViewCellStyleValue2: // case UITableViewCellStyleSubtitle: // // ... // default: // return; // } #pragma clang diagnostic pop |
参考链接:
http://nshipster.com/clang-diagnostics/
http://fuckingclangwarnings.com/
最新文章
- jquery 回车事件
- ASP.NET 5 单元测试中使用依赖注入
- 《BI项目笔记》创建多维数据集Cube(2)
- Android 学习第10课,Android的布局
- HTTPS实现原理
- Spring计划会议内容
- 【转载】Apache Kafka:下一代分布式消息系统
- 微信 回复多图文 借助php框架
- python 3.5 之 单双三引号
- swift学习 - 分类(Extensions)
- react 监听页面滚动
- 在进行多次scanf时,printf输出错误
- C#遍历枚举中所有值
- centos U盘挂载问题
- Lyk Love painting/convex hull/mumsic
- [Ramda] Lens in Depth
- linux 之sed
- gulp 编译es6 探究
- Selenium自动化测试基础
- 如何编写Makefile?