Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting semicolon after loop/if brackets

Is there any flag in GCC (like -Wempty-body in clang), that could help me detect semicolons after the braces of while/for loops? Sometimes it is very hard for humans to find these simple mistakes.

int i = 0;
for (i = 0; i < 10; ++i);
{
    cout << i << endl;
}

I use GCC 4.7.3 and clang 3.2-1~exp9ubuntu1.

Edited: I also check if compilers could help me find these mistakes after "if-else statements".

if (i == 0)
{
    cout << i << endl;
}
else;
{
    cout << i << endl;
}

What is interesting gcc is more helpful than clang (with this flags (-Wall -pedantic -Wempty-body) by printing warning:

main.cpp:30:9: warning: suggest braces around empty body in an ‘else’ statement [-Wempty-body]
like image 880
NiegodziwyBeru Avatar asked Jun 15 '13 19:06

NiegodziwyBeru


1 Answers

try

$gcc -Wempty-body foo.c

or

gcc -Wextra -c foo.c

like image 151
Abhas Tandon Avatar answered Oct 01 '22 17:10

Abhas Tandon