Compilation of boost_1_42_0 fails with errors. bash-3.2# g++ --version g++ (GCC) 4.5.0 bash-3.2# g++ -ftemplate-depth-128 -finline-functions -Wno-inline -Wall -dynamic -std=gnu++0x -fPIC -DBOOST_ALL_NO_LIB=1 -DBOOST_THREAD_BUILD_DLL=1 -DBOOST_THREAD_POSIX -DNDEBUG -I"." -c -o "bin.v2/libs/thread/build/darwin-4.5.0/release/threading-multi/pthread/thread.o" "libs/thread/src/pthread/thread.cpp" In file included from ./boost/thread/thread.hpp:22:0, from libs/thread/src/pthread/thread.cpp:10: ./boost/thread/detail/thread.hpp: In function 'boost::thread&& boost::move(boost::thread&&)': ./boost/thread/detail/thread.hpp:349:16: error: invalid initialization of reference of type 'boost::thread&&' from expression of type 'boost::thread' In file included from ./boost/thread/detail/thread_heap_alloc.hpp:17:0, from ./boost/thread/detail/thread.hpp:13, from ./boost/thread/thread.hpp:22, from libs/thread/src/pthread/thread.cpp:10: ./boost/thread/pthread/thread_heap_alloc.hpp: In function 'T* boost::detail::heap_new(A1&&) [with T = boost::detail::thread_data<void (*)()>, A1 = void (*&)()]': ./boost/thread/detail/thread.hpp:130:95: instantiated from here ./boost/thread/pthread/thread_heap_alloc.hpp:24:47: error: cannot bind 'void (*)()' lvalue to 'void (*&&)()' ./boost/thread/detail/thread.hpp:43:13: error: initializing argument 1 of 'boost::detail::thread_data<F>::thread_data(F&&) [with F = void (*)()]' bash-3.2#
bash-3.2# cat build.2.log Building the Boost C++ Libraries. After the build, the headers will be located at /usr/local/boost_1_42_0 The libraries will be located at /usr/local/boost_1_42_0/stage/lib Use 'bjam install --prefix=<path>' if you wish to install headers and libraries to a different location and remove the source tree. warning: Building Boost.Regex with the optional Unicode/ICU support disabled. note: Please refer to the Boost.Regex documentation for more information note: this is a strictly optional feature. warning: Graph library does not contain MPI-based parallel components. note: to enable them, add "using mpi ;" to your user-config.jam warning: skipping optional Message Passing Interface (MPI) library. note: to enable MPI support, add "using mpi ;" to user-config.jam. note: to suppress this message, pass "--without-mpi" to bjam. note: otherwise, you can safely ignore this message. ...patience... ...patience... ...patience... ...found 6637 targets... ...updating 8 targets... darwin.compile.c++ bin.v2/libs/thread/build/darwin-4.5.0/release/threading-multi/pthread/thread.o "g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -dynamic -no-cpp-precomp -gdwarf-2 -std=c++0x -fPIC -DBOOST_ALL_NO_LIB=1 -DBOOST_THREAD_BUILD_DLL=1 -DBOOST_THREAD_POSIX -DNDEBUG -I"." -c -o "bin.v2/libs/thread/build/darwin-4.5.0/release/threading-multi/pthread/thread.o" "libs/thread/src/pthread/thread.cpp" g++: unrecognized option '-no-cpp-precomp' In file included from ./boost/thread/thread.hpp:22:0, from libs/thread/src/pthread/thread.cpp:10: ./boost/thread/detail/thread.hpp: In function 'boost::thread&& boost::move(boost::thread&&)': ./boost/thread/detail/thread.hpp:349:16: error: invalid initialization of reference of type 'boost::thread&&' from expression of type 'boost::thread' In file included from ./boost/thread/detail/thread_heap_alloc.hpp:17:0, from ./boost/thread/detail/thread.hpp:13, from ./boost/thread/thread.hpp:22, from libs/thread/src/pthread/thread.cpp:10: ./boost/thread/pthread/thread_heap_alloc.hpp: In function 'T* boost::detail::heap_new(A1&&) [with T = boost::detail::thread_data<void (*)()>, A1 = void (*&)()]': ./boost/thread/detail/thread.hpp:130:95: instantiated from here ./boost/thread/pthread/thread_heap_alloc.hpp:24:47: error: cannot bind 'void (*)()' lvalue to 'void (*&&)()' ./boost/thread/detail/thread.hpp:43:13: error: initializing argument 1 of 'boost::detail::thread_data<F>::thread_data(F&&) [with F = void (*)()]' ...failed darwin.compile.c++ bin.v2/libs/thread/build/darwin-4.5.0/release/threading-multi/pthread/thread.o... ...skipped <pstage/lib>libboost_thread.dylib for lack of <pbin.v2/libs/thread/build/darwin-4.5.0/release/threading-multi>pthread/thread.o... ...skipped <pbin.v2/libs/thread/build/darwin-4.5.0/release/threading-multi>libboost_thread.dylib for lack of <pbin.v2/libs/thread/build/darwin-4.5.0/release/threading-multi>pthread/thread.o... ...skipped <pstage/lib>libboost_wave.dylib for lack of <pbin.v2/libs/thread/build/darwin-4.5.0/release/threading-multi>libboost_thread.dylib... darwin.compile.c++ bin.v2/libs/thread/build/darwin-4.5.0/release/link-static/threading-multi/pthread/thread.o "g++" -ftemplate-depth-128 -O3 -finline-functions -Wno-inline -Wall -no-cpp-precomp -gdwarf-2 -std=c++0x -DBOOST_ALL_NO_LIB=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_POSIX -DNDEBUG -I"." -c -o "bin.v2/libs/thread/build/darwin-4.5.0/release/link-static/threading-multi/pthread/thread.o" "libs/thread/src/pthread/thread.cpp" g++: unrecognized option '-no-cpp-precomp' In file included from ./boost/thread/thread.hpp:22:0, from libs/thread/src/pthread/thread.cpp:10: ./boost/thread/detail/thread.hpp: In function 'boost::thread&& boost::move(boost::thread&&)': ./boost/thread/detail/thread.hpp:349:16: error: invalid initialization of reference of type 'boost::thread&&' from expression of type 'boost::thread' In file included from ./boost/thread/detail/thread_heap_alloc.hpp:17:0, from ./boost/thread/detail/thread.hpp:13, from ./boost/thread/thread.hpp:22, from libs/thread/src/pthread/thread.cpp:10: ./boost/thread/pthread/thread_heap_alloc.hpp: In function 'T* boost::detail::heap_new(A1&&) [with T = boost::detail::thread_data<void (*)()>, A1 = void (*&)()]': ./boost/thread/detail/thread.hpp:130:95: instantiated from here ./boost/thread/pthread/thread_heap_alloc.hpp:24:47: error: cannot bind 'void (*)()' lvalue to 'void (*&&)()' ./boost/thread/detail/thread.hpp:43:13: error: initializing argument 1 of 'boost::detail::thread_data<F>::thread_data(F&&) [with F = void (*)()]' ...failed darwin.compile.c++ bin.v2/libs/thread/build/darwin-4.5.0/release/link-static/threading-multi/pthread/thread.o... ...skipped <pbin.v2/libs/thread/build/darwin-4.5.0/release/link-static/threading-multi>libboost_thread.a(clean) for lack of <pbin.v2/libs/thread/build/darwin-4.5.0/release/link-static/threading-multi>pthread/thread.o... ...skipped <pbin.v2/libs/thread/build/darwin-4.5.0/release/link-static/threading-multi>libboost_thread.a for lack of <pbin.v2/libs/thread/build/darwin-4.5.0/release/link-static/threading-multi>pthread/thread.o... ...skipped <pstage/lib>libboost_thread.a for lack of <pbin.v2/libs/thread/build/darwin-4.5.0/release/link-static/threading-multi>libboost_thread.a... ...failed updating 2 targets... ...skipped 6 targets... bash-3.2#
Can you attach the preprocessed source? This might be an issue with boost. There was a change with respect to rvalue references; lvalues cannot bind to rvalue references. The C++0x standard is changing still so this was a change with the standard between the releases of 4.4 and 4.5.
Subject: Re: Compiler flags error: error: invalid initialization of reference of type 'boost::thread&&' from expression of type 'boost::thread' Its attached. /Michah > > > ------- Comment #2 from pinskia at gcc dot gnu dot org 2010-04-28 02:00 ------- > Can you attach the preprocessed source? This might be an issue with boost. > There was a change with respect to rvalue references; lvalues cannot bind to > rvalue references. The C++0x standard is changing still so this was a change > with the standard between the releases of 4.4 and 4.5. > > > -- > > pinskia at gcc dot gnu dot org changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > Status|UNCONFIRMED |WAITING > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43915 > > ------- You are receiving this mail because: ------- > You are on the CC list for the bug, or are watching someone who is. > You reported the bug, or are watching the reporter.
Created attachment 20502 [details] Bzip'ed preprocessor output for "libs/thread/src/pthread/thread.cpp" with "g++" -c -save-temps -std=c++0x ... Bzip'ed thread.ii.
I think this error is correct: ./boost/thread/pthread/thread_heap_alloc.hpp: In function 'T* boost::detail::heap_new(A1&&) [with T = boost::detail::thread_data<void (*)()>, A1 = void (*&)()]': ./boost/thread/detail/thread.hpp:130:95: instantiated from here ./boost/thread/pthread/thread_heap_alloc.hpp:24:47: error: cannot bind 'void (*)()' lvalue to 'void (*&&)()' ./boost/thread/detail/thread.hpp:43:13: error: initializing argument 1 of 'boost::detail::thread_data<F>::thread_data(F&&) [with F = void (*)()]' A1 is deduced as an lvalue-reference, so reference-collapsing means that static_cast<A1&&> is a cast to an lvalue-reference, which won't bind to the rvalue-reference parameter. And I also think this error is correct: ./boost/thread/detail/thread.hpp: In function 'boost::thread&& boost::move(boost::thread&&)': ./boost/thread/detail/thread.hpp:349:16: error: invalid initialization of reference of type 'boost::thread&&' from expression of type 'boost::thread' Although the diagnostic is misleading. The code is: inline thread&& move(thread&& t) { return t; } At the point of return 't' is an lvalue so to return it as an rvalue it needs to be static_cast<thread&&>(t) I think this is INVALID
In this diagnostic: invalid initialization of reference of type 'boost::thread&&' from expression of type 'boost::thread' it might be clearer if the latter type was given as 'boost::thread&' so that it's clear it is an lvalue, otherwise it looks like it is failing to bind an rvalue-reference to a temporary, which should work. In fact it's try to bind the reference to an lvalue, which is invalid
N.B. I stopped testing boost trunk against gcc trunk ages ago and I don't think anyone does it these days, which means that boost releases often don't work with GCC versions that come out after the release, especially if they are using the experimental C++0x support. According to http://www.boost.org/users/news/version_1_42_0 Boost 1.42 was not tested with anything newer than 4.4.3 so it's unsurprising it doesn't use the new rvalue-reference rules that 4.5.0 implements This should be reported as a bug against Boost
(In reply to comment #6) > In this diagnostic: > > invalid initialization of reference of type 'boost::thread&&' from expression > of type 'boost::thread' > > it might be clearer if the latter type was given as 'boost::thread&' so that > it's clear it is an lvalue, otherwise it looks like it is failing to bind an > rvalue-reference to a temporary, which should work. Even better, the diagnostic could say "... from lvalue expression of type ..." Any change should probably wait until the dust settles on the lvalue/xvalue/prvalue taxonomy
Appended status to booost bug 3944 http://svn.boost.org/trac/boost/ticket/3844
I don't think we need to suspend this, it's not possible to return an rvalue-reference bound to an lvalue, the code is invalid.
The following shows how to patch, compile and use boost 1.43.0 with g++ -std=c++0x. At issue are the rvalue references and typecasts in the boost threading libraries. Simply tell Boost not to use its rvalue reference code when it gets compiled, even with option std=c++0x is set. Here's how: 1. Modify operatingSystem.jam, to compile with the -std=c+0x option. Also, remove the -no-cpp-precomp option if it is not supported by your compiler. For OS X I changed tools/build/v2/tools/darwin.jam at line 483 like this # Misc options. #flags darwin.compile OPTIONS : -no-cpp-precomp -gdwarf-2 ; flags darwin.compile OPTIONS : -std=c++0x -gdwarf-2 ; 2. Modify gcc.hpp to disable the conditional compilation of rvalue references (temporarily, until that part of the code works with g++) diff gcc.hpp.orig gcc.hpp 124c124,125 # define BOOST_HAS_RVALUE_REFS // # define BOOST_HAS_RVALUE_REFS # define BOOST_NO_RVALUE_REFERENCES In this manner you can compile and use Boost 1.43 fine gcc 4.5 or earlier, and still build your software to use the c++0x features supported by the gnu copmiler option -std=c++0x.
(In reply to comment #11) > > 2. Modify gcc.hpp to disable the conditional compilation of rvalue references > (temporarily, until that part of the code works with g++) > diff gcc.hpp.orig gcc.hpp > 124c124,125 > # define BOOST_HAS_RVALUE_REFS > // # define BOOST_HAS_RVALUE_REFS > # define BOOST_NO_RVALUE_REFERENCES Or you can do it without editing the boost headers by defining BOOST_COMPILER_CONFIG to refer to a modified version ofthe gcc.hpp header