I'm trying to find a GCC compiler flag that would cause GCC to refuse to compile the following code:
# include <stdio.h>
int main()
{
int x = 1;
if( (x = 10) ) {
printf("x is 10");
} else {
printf("x is not 10");
}
return 0;
}
The above code will compile with no warnings:
gcc -Wall -Werror -O3 -o x.exe x.c
Specifically, I want GCC to barf at the line if( (x = 10) )
. If I remove the inner brackets, GCC will break due to -Werror
gcc -Wall -Werror -O3 -o x.exe x.c
x.c: In function 'main':
x.c:7:9: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
if( x = 10 ) {
^
cc1.exe: all warnings being treated as errors
What I'm looking for is a way to force GCC to refuse to compile the code even when the brackets are present.
Thanks!