[/ / Copyright (c) 2015 Boost.Test contributors / / Distributed under the Boost Software License, Version 1.0. (See accompanying / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) /] [section:internal_details `BOOST_TEST`: details on expressions] Let's consider the following example: [bt_example boost_test_macro3..BOOST_TEST reporting..run-fail] It was already mentioned that the reporting is not symmetrical (see [link boost_test.testing_tools.reports here]). An expression is constructed from the `statement` appearing in the `BOOST_TEST` macro. This expression allows evaluation and reporting such as `"13 - 1 >= 12" failed` along with a copy of the `statement`, which contains more details than `"a - 1 < b" failed`. In details, what happens is the following: # a special object, the `seed` of the expression, is composed from the left side of `statement`. This initial composition has highest precedence over the supported operations. The expression below: a op1 b op2 c op3 d is actually seen as ( seed a ) op1 b op2 c op3 d # The "`seed a`" returns an `expression` object that keep tracks of the type of `a`. This expression has overloads for left-to-right associativity, and the operations `op1`, `op2` ... are /chained/ to the right of this expression object: a op1 b yields to the pseudo-code expression1 = create-expression(a) expression2 = create-expression(expression1, op1, b) `expression1` and `expression2` keep track of their left and right operands, and the operation on those operands. The expressions keep also track of the result type of the associated sub-expression. In the above example, `expression1` and `expression2` have result type `decltype(a)` and `decltype(a op1 b)` respectively. The result type allows for chaining sub-expressions. # The C++ operators precedence rules apply in any case. What is seen by the expression is what is reachable with left-to-right composition. Any other operation that happens before it reaches the expression's right operand is not parsed as a sub-expression and is seen as a single operand: the right operand is not developed further by the framework. Let's suppose `op2` below has higher precedence than `op1`, then a op1 b op2 c is equivalent to: create-expression(create-expression(a), op1, (b op2 c)) In the above statement, the final expression can only see the result of `(b op2 c)` to its right, for which no further detail can be provided in the logs. This is also the case for /right-to-left/ associative operators, such as `!`, `~`, `-` (unary negation) etc. [caution Since the `expression` object is composed from left-to-right, it actually observes a chain of operations and not the full expression tree.] # Once the full expression chain is built, it is evaluated as a chain of sub-expressions from left-to-right, exactly as the composition rule above. The evaluated elements are the ones of the expression itself. The expression a op1 b yields to the following evaluation chain: expression2.result = expression1.result op1 b expression1.result = a The final expression of the statement is cast to a boolean, which is in turn evaluated by the __UTF__. The example below illustrates the construction of the left-to-right /chained/ expression. [bt_example boost_test_macro2..BOOST_TEST compound statements..run-fail] [endsect]