Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix "Lexical or Preprocessor Issue - Extension used" warning in Xcode?

Tags:

xcode

ios

I've inherited a new project, which has several retain cycle warnings caused by implicitly retaining self within various blocks.

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

Lexical or Preprocessor Issue 
Extension used

I'm at a loss here-- what does this mean and how can I get rid of it?

like image 402
JRG-Developer Avatar asked Aug 26 '14 17:08

JRG-Developer


1 Answers

You get this warning for the use of typeof if "Pedantic Warnings" are enabled in the build settings. From the "Quick Help" for this setting:

Description Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++. For ISO C, follows the version of the ISO C standard specified by any -std option used. [GCC_WARN_PEDANTIC, -pedantic]

I am not an expert in (ISO) C standards, but according to 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. See Alternate Keywords.

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

The parser recognizes “asm” and “typeof” as keywords in gnu* modes; the variants “__asm__” and “__typeof__” are recognized in all modes.

you can use __typeof__ instead if you don't want to disable the warning:

__weak __typeof__(self) weakSelf = self;
like image 159
Martin R Avatar answered Nov 08 '22 09:11

Martin R