Take the 2-minute tour ×

When I add

#pragma GCC diagnostic error "-Wreturn-type"

the compiler produces warnings, not errors for each missing return. How can I make it turn this particular warning into an error?

Test code:

#pragma GCC diagnostic error "-Wreturn-type"

int foo(int x)
    if (x) return 8;

int main(int narg, char* arg[])

I have tried with


i686-apple-darwin10-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.6)

UPDATE: I have tried -Werror=return-type as suggested by @sastraxi, but it has the same effect.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

Try passing -Werror=return-type to gcc!

share|improve this answer
That is correct. But make it look like an answer, rather than a question. –  Nawaz Mar 23 '12 at 8:02
Just for you, Nawaz! :) –  sastraxi Mar 23 '12 at 8:03
It has the same effect — a warning, not an error. –  hamstergene Mar 23 '12 at 8:14
I get an error even without adding it, when running with g++ or gcc 4.5.2-8ubuntu4. –  sastraxi Mar 23 '12 at 8:19
It was my fault, I didn't read the question closely enough to see it was pre-4.4. If you want, you can use -Werror outright to turn all warnings into errors. –  sastraxi Mar 23 '12 at 8:26

Your Answer


