美文网首页
iOS编程 标注clang忽略编译器警告

iOS编程 标注clang忽略编译器警告

作者: Y_Eric | 来源:发表于2017-09-25 16:49 被阅读0次

在iOS开发过程中, 我们可能会碰到一些系统方法弃用, weak、循环引用、不能执行之类的警告,运用clang标注可以帮助你轻松解决。

// 插入需要忽略的相关代码 ⚠️

#pragma clang diagnostic push

#pragma clang diagnostic ignored "-Wundeclared-selector"

//插入需要忽略的相关代码(test方法在本类中不存在,ignored后加入"-Wundeclared-selector"编译器便忽略了此警告。)

[one performSelector:@selector(test) withObject:nil afterDelay:2.0];

#pragma clang diagnostic pop

//方法弃用告警 ⚠️

#pragmaclang diagnostic push

#pragmaclang diagnostic ignored "-Wdeprecated-declarations"

UIAlertView *alertViewTmp = [[UIAlertView alloc]initWithTitle:@""message:@""delegate:nil cancelButtonTitle:@""otherButtonTitles:@"", nil];

[alertViewTmp show];

#pragmaclang diagnostic pop

// 不兼容指针类型 ⚠️

#pragmaclang diagnostic push

#pragmaclang diagnostic ignored "-Wincompatible-pointer-types"

//

#pragmaclang diagnostic pop

//循环引用 ⚠️

#pragma clang diagnostic push

#pragma clang diagnostic ignored "-Warc-retain-cycles"

// self.completionBlock = ^ {//...// };

#pragma clang diagnostic pop

// 未使用变量 ⚠️

#pragmaclang diagnostic push

#pragmaclang diagnostic ignored "-Wunused-variable"

// inta;

#pragmaclang diagnostic pop

// 未使用default ⚠️

#pragmaclang diagnostic push

#pragmaclang diagnostic ignored "-Wcovered-switch-default"

// switch (style) {

// case UITableViewCellStyleDefault:

// case UITableViewCellStyleValue1:

// case UITableViewCellStyleValue2:

// case UITableViewCellStyleSubtitle:

// // ...

// default:

// return;

// }

#pragmaclang diagnostic pop

大家可以搜索需要忽略的警告编号,替换-Wundeclared-selector。(以下部分仅供参考)

-Wformat    invalid position specified for %select{field width|field precision}0

-Wformat    cannot mix positional and non-positional arguments in format string

-Wformat    values of type '%0' should not be used as format arguments add an explicit cast to %1 instead

-Wformat    format specifies type %0 but the argument has type %1

-Wformat    zero field width in scanf format string is unused

-Wformat    no closing ']' for '%%[' in scanf format string

-Wformat    format string should not be a wide string

-Wformat    format string contains '\\0' within the string body

-Wformat    '%select{*|.*}0' specified field %select{width|precision}0 is missing a matching 'int' argument

-Wformat    field %select{width|precision}0 should have type %1, but argument has type %2

-Wformat    %select{field width|precision}0 used with '%1' conversion specifier, resulting in undefined behavior

-Wformat    format string missing

-Wformat    incomplete format specifier-Wformat    flag '%0' results in undefined behavior with '%1' conversion specifier

-Wformat    flag '%0' is ignored when flag '%1' is present-Wformat    more '%%' conversions than data arguments

-Wformat    length modifier '%0' results in undefined behavior or no effect with '%1' conversion specifier

-Wformat-extra-args    data argument not used by format string

-Wformat-invalid-specifier    invalid conversion specifier '%0'

-Wformat-nonliteral    format string is not a string literal

-Wformat-security    format string is not a string literal (potentially insecure)

-Wformat-zero-length    format string is empty

-Wgcc-compat    GCC does not allow the 'cleanup' attribute argument to be anything other than a simple identifier

-Wglobal-constructors    declaration requires a global constructor

-Wglobal-constructors    declaration requires a global destructor

-Wgnu-conditional-omitted-operand    use of GNU ?: conditional expression extension, omitting middle operand

-Wheader-hygiene    using namespace directive in global context in header

-Widiomatic-parentheses    using the result of an assignment as a condition without parentheses

-Wignored-attributes    'malloc' attribute only applies to functions returning a pointer type

-Wignored-attributes    %0 attribute only applies to %select{functions|unions|variables and functions|functions and methods|parameters|functions, methods and blocks|functions, methods, and classes|functions, methods, and parameters|classes|variables|methods|variables, functions and labels|fields and global variables|structs|variables, functions and tag types|thread-local variables|variables and fields|variables, data members and tag types|types and namespaces|Objective-C interfaces}1

-Wignored-attributes    '%0' attribute cannot be specified on a definition

-Wignored-attributes    __weak attribute cannot be specified on an automatic variable when ARC is not enabled

-Wignored-attributes    Objective-C GC does not allow weak variables on the stack

-Wignored-attributes    __weak attribute cannot be specified on a field declaration

-Wignored-attributes    attribute %0 cannot be applied to %select{functions|Objective-C method}1 without return value

-Wignored-attributes    attribute declaration must precede definition

-Wignored-attributes    attribute %0 is ignored, place it after \"%select{class|struct|union|interface|enum}1\" to apply attribute to type declaration

-Wignored-attributes    __declspec attribute %0 is not supported

-Wignored-attributes    attribute %0 ignored, because it cannot be applied to a type

-Wignored-attributes    attribute %0 after definition is ignored

-Wignored-attributes    %0 attribute ignored

-Wignored-attributes    'sentinel' attribute only supported for variadic %select{functions|blocks}0

-Wignored-attributes    'sentinel' attribute requires named arguments

-Wignored-attributes    '%0' only applies to %select{function|pointer|Objective-C object or block pointer}1 types type here is %2

-Wignored-attributes    'nonnull' attribute applied to function with no pointer arguments

-Wignored-attributes    %0 attribute can only be applied to instance variables or properties

-Wignored-attributes    ibaction attribute can only be applied to Objective-C instance methods

-Wignored-attributes    %0 calling convention ignored on variadic function

-Wignored-attributes    %0 only applies to variables with static storage duration and functions

-Wignored-attributes    %0 attribute argument not supported: %1

-Wignored-attributes    #pramga ms_struct can not be used with dynamic classes or structures

-Wignored-attributes    transparent union definition must contain at least one field transparent_union attribute ignored

-Wignored-attributes    first field of a transparent union cannot have %select{floating point|vector}0 type %1 transparent_union attribute ignored

-Wignored-attributes    'gnu_inline' attribute requires function to be marked 'inline', attribute ignored

相关文章

  • iOS编程 标注clang忽略编译器警告

    在iOS开发过程中, 我们可能会碰到一些系统方法弃用, weak、循环引用、不能执行之类的警告,运用clang标注...

  • iOS编程 手动忽略clang编译器警告

    在iOS开发过程中, 我们可能会碰到一些系统方法弃用, weak、循环引用、不能执行之类的警告。 有代码洁癖的孩子...

  • #pragma警告

    一:忽略源文件中的警告,使用编译器宏来操作 pragma clang diagnostic ignored "警告...

  • 忽略clang编译器警告

    参考链接今天看 MJRefresh 源码有一段忽略获的代码,借机整理下相关内容 #pragma在本质上是声明,常用...

  • iOS 编译过程的原理和应用

    前言 __attribute__ Clang警告处理 预处理 插入编译期脚本 提高项目编译速度 iOS编译 编译器...

  • iOS手动忽略clang警告

    对于有代码洁癖的人来说,警告⚠️是非常烦人的,特别是对于一些系统弃用的方法你又不能把它干掉或者用新的API替换,这...

  • ios 开发中常见警告处理

    ios 开发中常见警告处理例如: pragma clang diagnostic pushpragma clang...

  • iOS开发小记

    字体拉伸 clang重写.m文件为.cpp文件 忽略警告 忽略单个警告 其中相关命令通过右击对应的警告,Revea...

  • Clang忽略警告汇集

    1.retain cycle 2.不兼容指针类型 3.方法启用告警 4.未使用变量 5.sel中使用了不存在的方法...

  • iOS去掉烦人的警告

    在iOS开发过程中,偶尔会碰到一些编译器警告,如果能够确定该警告不会影响到程序的正常运行,则可以手动告诉编译器忽略...

网友评论

      本文标题:iOS编程 标注clang忽略编译器警告

      本文链接:https://www.haomeiwen.com/subject/sfldextx.html