[cfe-dev] [PATCH] Make libcxx compile on x86_64 Linux w/ g++ 4.4.3

Matt Johnson johnso87 at illinois.edu
Wed Jun 2 00:35:12 PDT 2010


Hi,
Just thought I'd contribute a small patch that helped libcxx compile on 
my machine using g++ 4.4.3 with -std=c++0x. Without it I got the 
following message:

+ g++ -std=c++0x -c -g -Os -fPIC -nostdinc++ -I../include 
../src/condition_variable.cpp
In file included from ../src/condition_variable.cpp:11:
../include/thread: In member function ‘std::__1::thread& 
std::__1::thread::operator=(std::__1::thread&&)’:
../include/thread:268: error: no match for ‘operator!=’ in 
‘((std::__1::thread*)this)->std::__1::thread::__t_ != 
std::__1::__get_nullptr_t()’
../include/system_error:569: note: candidates are: bool 
std::__1::operator!=(const std::__1::error_condition&, const 
std::__1::error_condition&)
../include/system_error:565: note: bool std::__1::operator!=(const 
std::__1::error_condition&, const std::__1::error_code&)
../include/system_error:561: note: bool std::__1::operator!=(const 
std::__1::error_code&, const std::__1::error_condition&)
../include/system_error:557: note: bool std::__1::operator!=(const 
std::__1::error_code&, const std::__1::error_code&)
../include/cstddef:73: note: bool 
std::__1::operator!=(std::__1::nullptr_t, std::__1::nullptr_t)
../include/thread:271: error: cannot convert ‘std::__1::nullptr_t’ to 
‘pthread_t’ in assignment

This happens because nullptr is not convertible or comparable to 
integral types (except bool), only pointers and pointer-to-members 
(http://en.wikipedia.org/wiki/C%2B%2B0x#Null_pointer_constant), so you 
can't use it to check or set __t, at least not directly. There's 
probably a better way to do it than this, just thought I'd bring the 
matter to your attention. For what it's worth, I haven't hacked the test 
script to run on my machine yet so I haven't tested it, but it does 
compile with minimal #warnings about exception_ptr not being implemented.

mrj10 at mjlap:~/llvm/libcxx/include$ svn diff thread
Index: thread
===================================================================
--- thread (revision 105315)
+++ thread (working copy)
@@ -265,10 +265,12 @@
thread&
thread::operator=(thread&& __t)
{
- if (__t_ != nullptr)
+ //if (__t_ != nullptr)
+ if (__t_ != NULL)
terminate();
__t_ = __t.__t_;
- __t.__t_ = nullptr;
+ //__t.__t_ = nullptr;
+ __t.__t_ = NULL;
return *this;
}

Thanks,
Matt

-- 
Matt Johnson
Graduate Student
University of Illinois at Urbana-Champaign, Dept. of ECE
Coordinated Science Lab, Rm. 213




More information about the cfe-dev mailing list