Warning "Use of GNU statement expression extension"
Asked Answered
L

4

15

I have this Objective-C istruction:

NSRange range = NSMakeRange(i, MIN(a, b));

where a and bare NSUIntegers.

MIN() is the macro defined in the standard NSObjCRuntime.hheader file as:

#if !defined(MIN)
   #define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
#endif

During the compilation, the LLVM Compiler 4.1 highlights my instruction showing the warning: "Use of GNU statement expression extension".

What does this mean? Is it my fault? If yes, how can I fix it? If not, how can I remove the compiler warning?

Lamed answered 26/10, 2012 at 12:37 Comment(0)
N
11

It’s a late answer, I know, but you can avoid this message by adding -Wno-gnu to your compiler flags.

(In Xcode 5 I believe you can change this by going to your project’s Build Settings and adding -Wno-gnu to the “Other C Flags”, which are in the “Apple LLVM 5.0 – Custom Compiler Flags” section.)

Nearly answered 16/12, 2013 at 21:28 Comment(0)
K
12

"Statement expressions" is an extension of the GNU C compiler and allows you to execute a group of statements, returning the value of the last statement:

x = ({
    statement1;
    statement2;
    statement3;
});

In the above example, x will have the value returned by statement3.

It is a convenient feature that enables you to have multi-statement macros that can be nested easily into other expressions. It is not, however, defined by any C standard.

Kehr answered 26/10, 2012 at 12:44 Comment(2)
Thank you, very interesting. Since the MIN() macro is defined in the Apple headers (which I can't obviously change), there is a way to suppress this warning in my code?Lamed
@Lamed You should just be able to do #undef MIN. That goes for all #define s.Acalia
N
11

It’s a late answer, I know, but you can avoid this message by adding -Wno-gnu to your compiler flags.

(In Xcode 5 I believe you can change this by going to your project’s Build Settings and adding -Wno-gnu to the “Other C Flags”, which are in the “Apple LLVM 5.0 – Custom Compiler Flags” section.)

Nearly answered 16/12, 2013 at 21:28 Comment(0)
D
10

Don't use -Wno-gnu, that shuts down too many warnings. Instead, use:

-Wno-gnu-statement-expression
Duffel answered 27/8, 2018 at 15:57 Comment(2)
the pragma statement would be: #pragma GCC diagnostic ignored "-Wgnu-statement-expression" Philomenaphiloo
@Philomenaphiloo With that, I get error: unknown option after ‘#pragma GCC diagnostic’ kind [-Werror=pragmas]. I'm compiling with -Wall -Wextra -pedantic -Werror. Any idea?Honegger
L
2

Statement expressions have been declared.

You can selectively ignore the warning by using pragma codes without changing project settings.

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu"

NSRange range = NSMakeRange(i, MIN(a, b));

#pragma GCC diagnostic pop
Luster answered 3/1, 2015 at 0:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.