www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - assert bug

reply Tiago Gasiba <tiago.gasiba gmail.com> writes:
The following code compiles OK but behaves differently if you change the
function return value from double to void:

double f(  double p ){
//void f(  double p ){
  assert( p>0.0 );
}

int main( ){
  double p = 10.01;

  f( p );

  return 0;
}

Tiago

-- 
Tiago Gasiba (M.Sc.) - http://www.gasiba.de
Everything should be made as simple as possible, but not simpler.
Nov 23 2005
parent reply zwang <nehzgnaw gmail.com> writes:
Tiago Gasiba wrote:
 The following code compiles OK but behaves differently if you change the
function return value from double to void:
 
 double f(  double p ){
 //void f(  double p ){
   assert( p>0.0 );
 }
 
 int main( ){
   double p = 10.01;
 
   f( p );
 
   return 0;
 }
 
 Tiago
 

Nothing wrong here. When the return type is not void, and your function doesn't return a value, dmd inserts an "assert(0);" at the end of the function.
Nov 23 2005
parent Tiago Gasiba <tiago.gasiba gmail.com> writes:
zwang schrieb:

 Tiago Gasiba wrote:
 The following code compiles OK but behaves differently if you change the
 function return value from double to void:
 
 double f(  double p ){
 //void f(  double p ){
   assert( p>0.0 );
 }
 
 int main( ){
   double p = 10.01;
 
   f( p );
 
   return 0;
 }
 
 Tiago
 

Nothing wrong here. When the return type is not void, and your function doesn't return a value, dmd inserts an "assert(0);" at the end of the function.

True. Shame on me :) I have found a bug on assert, though, that crashes with SIGSEGV. I'll try to reproduce it again and then post it. Tiago -- Tiago Gasiba (M.Sc.) - http://www.gasiba.de Everything should be made as simple as possible, but not simpler.
Nov 23 2005