Including Xutil.h on Fedora breaks BOOST_FOREACH

Compiling this: #include <X11/Xutil.h> #include <boost/shared_ptr.hpp> #include <vector> #include <cstdlib> #include <boost/foreach.hpp> #include <iostream> using std::ostream; class Value { public: explicit Value(int amount) : m_amount(amount) {} void WriteTo(ostream& stream) const { stream << m_amount; } private: int m_amount; }; ostream& operator <<(ostream& stream, const Value& value) { value.WriteTo(stream); return stream; } int main() { typedef boost::shared_ptr<Value> ValuePtr; std::vector<ValuePtr> valueBuffer; for(int count = 0; 10 > count; ++count){ valueBuffer.push_back(ValuePtr(new Value(::rand()))); } BOOST_FOREACH(ValuePtr value, valueBuffer){ std::cout << *value << std::endl; } return 0; } on Fedora 10 (Intel) produces error output like: /usr/include/boost/foreach.hpp:223: error: expected nested-name-specifier before ‘int’ /usr/include/boost/foreach.hpp:223: error: two or more data types in declaration of ‘parameter’ /usr/include/boost/foreach.hpp:224: error: default template arguments may not be used in function templates Value.cpp: In function ‘int main()’: Value.cpp:34: error: no matching function for call to ‘not_(boost::is_array<std::vector<boost::shared_ptr<Value>, std::allocator<boost::shared_ptr<Value> > > >*)’ Value.cpp:34: error: no matching function for call to ‘not_(boost::foreach::is_noncopyable<std::vector<boost::shared_ptr<Value>, std::allocator<boost::shared_ptr<Value> > > >*)’ Value.cpp:34: error: no matching function for call to ‘not_(boost::is_array<std::vector<boost::shared_ptr<Value>, std::allocator<boost::shared_ptr<Value> > > >*)’ Value.cpp:34: error: no matching function for call to ‘not_(boost::foreach::is_noncopyable<std::vector<boost::shared_ptr<Value>, std::allocator<boost::shared_ptr<Value> > > >*)’ Value.cpp:34: error: no matching function for call to ‘not_(boost::is_array<std::vector<boost::shared_ptr<Value>, std::allocator<boost::shared_ptr<Value> > > >*)’ Value.cpp:34: error: no matching function for call to ‘not_(boost::foreach::is_noncopyable<std::vector<boost::shared_ptr<Value>, std::allocator<boost::shared_ptr<Value> > > >*)’ If the first included header file is removed from the code, it builds successfully. Even though the code in this example doesn't technically need that first header file included, it is representative of code that does. What is needed so this code can build successfully while including all the header files?

Tron Thomas wrote:
#include <X11/Xutil.h>
A quick search on Google Codesearch shows that Xutil.h includes Xlib.h which has the following " #define Bool int #define Status int #define True 1 #define False 0 " (around line 112 in the version I am looking at). This breaks Boost.ForEach's (legitimate) attempt to use "Bool" as the name for a template type. How to fix? Some possibilities a) Stop using libraries that employ such bad practices, or b) Wrap the include in your own header that tidies up after X11 with some #undefs, or c) include X11 after Boost ?! I doubt Boost.ForEach would be the only library the X11 include would foul up.

Pete Bartlett wrote:
Tron Thomas wrote:
#include <X11/Xutil.h>
A quick search on Google Codesearch shows that Xutil.h includes Xlib.h which has the following
" #define Bool int #define Status int #define True 1 #define False 0 "
(around line 112 in the version I am looking at).
This breaks Boost.ForEach's (legitimate) attempt to use "Bool" as the name for a template type. How to fix? Some possibilities
a) Stop using libraries that employ such bad practices, or b) Wrap the include in your own header that tidies up after X11 with some #undefs, or c) include X11 after Boost ?!
d) Work around it in Boost.Foreach, which has already been done for the next release.
I doubt Boost.ForEach would be the only library the X11 include would foul up.
Perhaps someone with an interest in X11 could file a bug against them. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (3)
-
Eric Niebler
-
Pete Bartlett
-
Tron Thomas