简体   繁体   English

在Xcode中修复“Lexical或Preprocessor Issue - Extension used”警告?

[英]Fix “Lexical or Preprocessor Issue - Extension used” warning in Xcode?

I've inherited a new project, which has several retain cycle warnings caused by implicitly retaining self within various blocks. 我继承了一个新项目,该项目有多个保留周期警告,这些警告是通过在各个块中隐式保留self来实现的。

In attempting to fix these, I've written 在尝试解决这些问题时,我写了

__weak typeof(self) weakSelf = self;

to create a weak reference for use within the block. 创建一个弱的引用以便在块中使用。

However, Xcode v. 5.1.1 is giving the cryptic warning 但是,Xcode v.5.1.1给出了神秘的警告

Lexical or Preprocessor Issue 
Extension used

I'm at a loss here-- what does this mean and how can I get rid of it? 我在这里不知所措 - 这是什么意思,我怎么能摆脱它?

You get this warning for the use of typeof if "Pedantic Warnings" are enabled in the build settings. 如果在构建设置中启用了“Pedantic Warnings”,则会出现使用typeof警告。 From the "Quick Help" for this setting: 从此设置的“快速帮助”:

Description Issue all the warnings demanded by strict ISO C and ISO C++; 描述发出严格的ISO C和ISO C ++要求的所有警告; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++. 拒绝所有使用禁止扩展的程序,以及其他一些不遵循ISO C和ISO C ++的程序。 For ISO C, follows the version of the ISO C standard specified by any -std option used. 对于ISO C,遵循由任何使用的-std选项指定的ISO C标准的版本。 [GCC_WARN_PEDANTIC, -pedantic] [GCC_WARN_PEDANTIC,-pedantic]

I am not an expert in (ISO) C standards, but according to https://gcc.gnu.org/onlinedocs/gcc/Typeof.html : 我不是(ISO)C标准的专家,但根据https://gcc.gnu.org/onlinedocs/gcc/Typeof.html

If you are writing a header file that must work when included in ISO C programs, write __typeof__ instead of typeof . 如果您正在编写包含在ISO C程序中必须工作的头文件,请编写__typeof__而不是typeof See Alternate Keywords. 请参阅备用关键字。

and http://clang.llvm.org/docs/UsersManual.html : http://clang.llvm.org/docs/UsersManual.html

The parser recognizes “ asm ” and “ typeof ” as keywords in gnu* modes; 解析器将“ asm ”和“ typeof ”识别为gnu *模式中的关键字; the variants “ __asm__ ” and “ __typeof__ ” are recognized in all modes. 变体“ __asm__ ”和“ __typeof__ ”在所有模式中都被识别。

you can use __typeof__ instead if you don't want to disable the warning: 如果您不想禁用警告,则可以使用__typeof__

__weak __typeof__(self) weakSelf = self;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM