Opened 7 years ago

#11705 new Bugs

Phoenix function defining operator() with non-const reference parameter fails to compile with C++ 11.

Reported by: David Williams <bateyware@…> Owned by: Thomas Heller
Milestone: To Be Determined Component: phoenix
Version: Boost 1.59.0 Severity: Problem
Keywords: phoenix function, C++ 11, result_of Cc:

Description

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.

Attachments (3)

phxfunction_test_problem.cpp (3.4 KB ) - added by David Williams <bateyware@…> 7 years ago.
Small test program to illustrate the problem.
function_testsCallsFailCompileLog.txt (20.0 KB ) - added by David Williams <bateyware@…> 7 years ago.
clang compiler build log (Clang 3.5 with Xcode 6.2) that shows the compilation errors generated.
updatedPhoenixFunctionProblemBuildLog.txt (20.1 KB ) - added by David Williams <bateyware@…> 7 years ago.
Updated compiler build log that shows the errors. I have updated the log to reflect a minor change relating to the file name of the test program.

Download all attachments as: .zip

Change History (3)

by David Williams <bateyware@…>, 7 years ago

Small test program to illustrate the problem.

by David Williams <bateyware@…>, 7 years ago

clang compiler build log (Clang 3.5 with Xcode 6.2) that shows the compilation errors generated.

by David Williams <bateyware@…>, 7 years ago

Updated compiler build log that shows the errors. I have updated the log to reflect a minor change relating to the file name of the test program.

Note: See TracTickets for help on using tickets.