[Boost-bugs] [Boost C++ Libraries] #5578: non-mutable local variables in phoenix

Subject: [Boost-bugs] [Boost C++ Libraries] #5578: non-mutable local variables in phoenix
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-05-27 23:09:45


#5578: non-mutable local variables in phoenix
------------------------------+---------------------------------------------
 Reporter: anonymous | Owner: theller
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: phoenix
  Version: Boost 1.46.1 | Severity: Problem
 Keywords: |
------------------------------+---------------------------------------------
 Phoenix local variables are non-mutable with the test case below. It seems
 like making a local variable non-mutable in these cases is the wrong thing
 to do.

 If you follow my logic:
   * TEST1 -- the local is a ref to the variable i
   * TEST2 -- the local is an int containing the value from arg1 or i (and
 is mutable)
   * TEST3 -- I would ''expect'' the local to be an into containing the
 value from arg1... but it doesn't compile because it things the local is
 immutable
   * TEST4 -- I would ''expect'' this to work the same as TEST3


 {{{
 #!cpp
 #define TEST3

 #include <iostream>
 #include <boost/phoenix/phoenix.hpp>

 int main()
 {
    using namespace boost::phoenix;
    using namespace boost::phoenix::arg_names;
    using namespace boost::phoenix::local_names;


 #ifdef TEST1
    std::cout << "TEST1" << std::endl;
    /**
     * This will print 41 41.
     * _a is a local variable that is a reference to i. This is a little
 surprising
     * at first but not too bad. We can deal with it.
     */
    int i = 42;
    let( _a = arg1 )
    [
       std::cout << --_a
    ](i);

    std::cout << ' ' << i << std::endl;

 #endif // TEST1


 #ifdef TEST2
    std::cout << "TEST2" << std::endl;
    /**
     * This will print 41 42.
     * _a is a local variable initialized with the value of arg1. Makes
 sense
     */
    int i = 42;
    let( _a = val(arg1) )
    [
       std::cout << --_a
    ](i);

    std::cout << ' ' << i << std::endl;

 #endif // TEST2



 #ifdef TEST3
    std::cout << "TEST3" << std::endl;
    /**
     * This wont compile because _a is not mutable. This is not only
     * surprising but makes local scoped variables have very limited use.
     */
    let( _a = val(arg1) )
    [
       std::cout << --_a
    ](42);

 #endif // TEST3



 #ifdef TEST4
    std::cout << "TEST4" << std::endl;
    /**
     * This fails for the same reason... I would expect it to work also.
     */
    let( _a = val(42) )
    [
       std::cout << --_a
    ]();

 #endif // TEST4


    return 1;
 }

 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/5578>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC