Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r75944 - in trunk/tools/build/v2: engine test/core-language
From: steven_at_[hidden]
Date: 2011-12-14 16:33:27


Author: steven_watanabe
Date: 2011-12-14 16:33:26 EST (Wed, 14 Dec 2011)
New Revision: 75944
URL: http://svn.boost.org/trac/boost/changeset/75944

Log:
Fix a subtle problem in the result of if statements.
Text files modified:
   trunk/tools/build/v2/engine/function.c | 8 ++---
   trunk/tools/build/v2/test/core-language/test.jam | 55 ++++++++++++++++++++++++++++++++++++++++
   2 files changed, 58 insertions(+), 5 deletions(-)

Modified: trunk/tools/build/v2/engine/function.c
==============================================================================
--- trunk/tools/build/v2/engine/function.c (original)
+++ trunk/tools/build/v2/engine/function.c 2011-12-14 16:33:26 EST (Wed, 14 Dec 2011)
@@ -2167,19 +2167,18 @@
     }
     else if( parse->type == PARSE_IF )
     {
- int nested_result = result_location == RESULT_NONE? RESULT_NONE : RESULT_RETURN;
         int f = compile_new_label( c );
         /* Emit the condition */
         compile_condition( parse->left, c, 0, f );
         /* Emit the if block */
- compile_parse( parse->right, c, nested_result );
- if ( parse->third->type != PARSE_NULL )
+ compile_parse( parse->right, c, result_location );
+ if ( parse->third->type != PARSE_NULL || result_location != RESULT_NONE )
         {
             /* Emit the else block */
             int end = compile_new_label( c );
             compile_emit_branch( c, INSTR_JUMP, end );
             compile_set_label( c, f );
- compile_parse( parse->third, c, nested_result );
+ compile_parse( parse->third, c, result_location );
             compile_set_label( c, end );
         }
         else
@@ -2187,7 +2186,6 @@
             compile_set_label( c, f );
         }
 
- adjust_result( c, nested_result, result_location);
     }
     else if( parse->type == PARSE_WHILE )
     {

Modified: trunk/tools/build/v2/test/core-language/test.jam
==============================================================================
--- trunk/tools/build/v2/test/core-language/test.jam (original)
+++ trunk/tools/build/v2/test/core-language/test.jam 2011-12-14 16:33:26 EST (Wed, 14 Dec 2011)
@@ -359,6 +359,61 @@
 
 check-order if-else-false : r2 ;
 
+rule test-rule
+{
+ if true
+ {
+ return result ;
+ }
+}
+
+check-equal if-true-result : [ test-rule ] : result ;
+
+rule test-rule
+{
+ local idx = 1 2 ;
+ local values = true ;
+ while $(idx)
+ {
+ local v = $(values[$(idx[1])]) ;
+ idx = $(idx[2-]) ;
+ if $(v)
+ {
+ return result ;
+ }
+ }
+}
+
+check-equal if-false-result : [ test-rule ] : ;
+
+rule test-rule
+{
+ if true
+ {
+ return r1 ;
+ }
+ else
+ {
+ return r2 ;
+ }
+}
+
+check-equal if-else-true-result : [ test-rule ] : r1 ;
+
+rule test-rule
+{
+ if $(false)
+ {
+ return r1 ;
+ }
+ else
+ {
+ return r2 ;
+ }
+}
+
+check-equal if-else-false-result : [ test-rule ] : r2 ;
+
 }
 
 # Check the evaluation of conditions


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk