> On Dec. 17, 2014, 11:36 p.m., Dominic Hamon wrote:
> > any idea what is missing from g++ 4.6 that causes this failure?

It's a bug in the `<tr1/functional>` header. The `operator()`'s implementation 
doesn't perfect-forward the args correctly.

```cpp
#include <tr1/functional>

void F(int&& x) {}

void G(const std::tr1::function<void(int&&)>& x) {
  x(42);
}

int main() {
  G(F);
}
```

```
In file included from a.cc:1:0:
/usr/include/c++/4.6/tr1/functional: In member function ‘_Res 
std::tr1::function<_Res(_ArgTypes ...)>::operator()(_ArgTypes ...) const [with 
_Res = void, _ArgTypes = {int&&}]’:
a.cc:7:7:   instantiated from here
/usr/include/c++/4.6/tr1/functional:2040:46: error: invalid initialization of 
reference of type ‘int&&’ from expression of type ‘int’
/usr/include/c++/4.6/tr1/functional:2040:46: error: return-statement with a 
value, in function returning 'void' [-fpermissive]
/usr/include/c++/4.6/tr1/functional: In static member function ‘static void 
std::tr1::_Function_handler<void(_ArgTypes ...), _Functor>::_M_invoke(const 
std::tr1::_Any_data&, _ArgTypes ...) [with _Functor = void (*)(int&&), 
_ArgTypes = {int&&}]’:
/usr/include/c++/4.6/tr1/functional:2021:6:   instantiated from 
‘std::tr1::function<_Res(_ArgTypes ...)>::function(_Functor, typename 
__gnu_cxx::__enable_if<(! std::tr1::is_integral<_Functor>::value), 
std::tr1::function<_Res(_ArgTypes ...)>::_Useless>::__type) [with _Functor = 
void (*)(int&&), _Res = void, _ArgTypes = {int&&}, typename 
__gnu_cxx::__enable_if<(! std::tr1::is_integral<_Functor>::value), 
std::tr1::function<_Res(_ArgTypes ...)>::_Useless>::__type = 
std::tr1::function<void(int&&)>::_Useless]’
a.cc:11:6:   instantiated from here
/usr/include/c++/4.6/tr1/functional:1684:9: error: invalid initialization of 
reference of type ‘int&&’ from expression of type ‘int’
```

The `<functional>` header correctly perfect-forwards the arguments so we can 
make the above program by simply switching from `std::tr1::function` to 
`std::function`.

```cpp
#include <functional>

void F(int&& x) {}

void G(const std::function<void(int&&)>& x) {
  x(42);
}

int main() {
  G(F);
}
```


- Michael


-----------------------------------------------------------
This is an automatically generated e-mail. To reply, visit:
https://reviews.apache.org/r/29180/#review65386
-----------------------------------------------------------


On Dec. 17, 2014, 11:33 p.m., Michael Park wrote:
> 
> -----------------------------------------------------------
> This is an automatically generated e-mail. To reply, visit:
> https://reviews.apache.org/r/29180/
> -----------------------------------------------------------
> 
> (Updated Dec. 17, 2014, 11:33 p.m.)
> 
> 
> Review request for mesos, Benjamin Hindman and Dominic Hamon.
> 
> 
> Bugs: MESOS-2192
>     https://issues.apache.org/jira/browse/MESOS-2192
> 
> 
> Repository: mesos-git
> 
> 
> Description
> -------
> 
> Fixed a compilation issue in GCC 4.6.
> 
> 
> Diffs
> -----
> 
>   3rdparty/libprocess/include/process/clock.hpp 
> 1fd418b31133fd5a5444095ac887c77ee9375b2d 
>   3rdparty/libprocess/src/clock.cpp dfe9ced2415b8567abb8c137ab73d90b59164d67 
>   3rdparty/libprocess/src/process.cpp 
> 028b33e7ecb7e0a39334ac4ab0279ee327a72a56 
> 
> Diff: https://reviews.apache.org/r/29180/diff/
> 
> 
> Testing
> -------
> 
> make check
> 
> 
> Thanks,
> 
> Michael Park
> 
>

Reply via email to