www.digitalmars.com         C & C++   DMDScript  

c++ - Wrong warning (18)

reply Adder <Adder_member pathlink.com> writes:
Hello,

The following code:

int f ()
{ throw 10; }
int main ()
{ return 0; }

produces:

Warning 18: implied return of f at closing '}' does not return value


Can you please provide a way to disable warnings via #pragma's
and push/pop these settings so that warnings are disabled only for some
sections of the code ? I wouldn't like to turn off this warning for the entire
code.


(For example, with Borland, one can write:

#pragma option push
#pragma warn-par
..
#pragma option pop

)


Thanks,
Adder
Apr 06 2006
parent reply Walter Bright <newshound digitalmars.com> writes:
Adder wrote:
 Hello,
 
 The following code:
 
 int f ()
 { throw 10; }
 int main ()
 { return 0; }
 
 produces:
 
 Warning 18: implied return of f at closing '}' does not return value
 
 
 Can you please provide a way to disable warnings via #pragma's
 and push/pop these settings so that warnings are disabled only for some
 sections of the code ? I wouldn't like to turn off this warning for the entire
 code.
 
 
 (For example, with Borland, one can write:
 
 #pragma option push
 #pragma warn-par
 ..
 #pragma option pop
 
 )
An easier way to turn off the warning is to rewrite as: int f() { throw 10; return 0; }
Apr 06 2006
parent reply Adder <Adder_member pathlink.com> writes:
An easier way to turn off the warning is to rewrite as:
int f()
{   throw 10;
     return 0;
}
True... But then the other compiler complains about "Unreachable code in function f" :D However, that can be solved by disabling the warning. For the other compiler. Thanks !
Apr 06 2006
parent Walter Bright <newshound digitalmars.com> writes:
Adder wrote:
 An easier way to turn off the warning is to rewrite as:
...
 But then the other compiler complains about "Unreachable code in function f" :D
That's why I hate warnings <g>.
Apr 06 2006