Subject: [Boost-bugs] [Boost C++ Libraries] #11705: Phoenix function defining operator() with non-const reference parameter fails to compile with C++ 11.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-10-03 05:07:56
#11705: Phoenix function defining operator() with non-const reference parameter
fails to compile with C++ 11.
-------------------------------------------------+---------------------
Reporter: David Williams <bateyware@â¦> | Owner: theller
Type: Bugs | Status: new
Milestone: To Be Determined | Component: phoenix
Version: Boost 1.59.0 | Severity: Problem
Keywords: phoenix function, C++ 11, result_of |
-------------------------------------------------+---------------------
A phoenix function object defining operator() with a non-const reference
parameter does not compile when using clang version 3.5 in C++ 11 mode.
The compiler used is: Apple LLVM version 6.0 (clang-600.0.57) (based on
LLVM 3.5svn)
The Boost version used is 1.59.
A test program to illustrate the problem along with the compiler build log
are provided with this bug report.
An example of such a function object that reproduces the problem is the
following:
struct add_int_impl
{
typedef int result_type;
add_int_impl(int v)
{
_value=v;
}
int operator()(bool& flag) const
{
std::cout << "int operator()(bool& flag) called" << std::endl;
if (_value == 4)
flag=true;
return _value;
}
int _value;
};
The function can be tested with the following code snippet:
// *** Begin code snippet ***
// Initialise the function with the value 4.
boost::phoenix::function<add_int_impl> add_int(4);
bool flag=false;
BOOST_TEST(add_int(arg1)(flag) == (4));
// *** End code snippet ***
This call will only compile under Apple's version of clang 3.5 in C++ 11
mode when one or both of the
following conditions are met;
1) The int operator()(int a) const is also defined
2) One of the following flags is defined:
BOOST_RESULT_OF_TR1
BOOST_RESULT_OF_USE_TR1_WITH_DECLTYPE_FALLBACK
The program also compiles if the function signature is changed to use a
const
reference parameter, i.e. int operator()(const bool& flag) const.
However this then means that the parameter value cannot be
modified within the body of the function as required.
The problem does not occur if the program is compiled using C++ 98
compatibility mode.
I suspect that the problem relates to the use of boost::result_of, which
uses the decltype() function
to deduce function return types when compiling with C++ 11 support.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11705> 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:19 UTC