由于“signed char”和“char”,系统头文件中的重定义错误

我试图包含这个文件

boost/assign/list_of.hpp 

但我有这个编译器的错误

 /usr/include/boost/type_traits/is_integral.hpp:38: error: redefinition of struct boost::is_integral<char> /usr/include/boost/type_traits/is_integral.hpp:32: error: previous definition of struct boost::is_integral<char> 

文件is_integral.hpp中的这些定义行(32,38)是:

 BOOST_TT_AUX_BOOL_TRAIT_CV_SPEC1(is_integral,signed char,true) BOOST_TT_AUX_BOOL_TRAIT_CV_SPEC1(is_integral,char,true) 

如何解决编译问题? 编译器是gcc版本4.4.7 20120313操作系统是红帽企业Linux服务器版本6.5(圣地亚哥)

从C ++标准

3.9.1基本类型[basic.fundamental]

声明为字符(char)的对象应该足够大,以存储实现的基本字符集的任何成员。 如果来自该组的字符存储在字符对象中,则该字符对象的整数值等于该字符的单个字符字面值形式的值。 char对象是否可以保存负值是实现定义的。 字符可以显式地声明为无符号或有符号的。 Plain char,signed char和unsigned char是三种不同的类型 。 char,signed char和unsigned char占用相同的存储量,并具有相同的对齐要求(basic.types); 也就是说,它们具有相同的对象表示。 对于字符类型,对象表示的所有位都参与到值表示中。 对于无符号字符类型,值表示的所有可能位模式都表示数字。 这些要求不适用于其他类型。 在任何特定的实现中,一个普通的char对象可以采用与signed char或unsigned char相同的值; 哪一个是实现定义的。

charunsigned charsigned char是三个不同的类型, boost::is_integral对于这三种类型应该是特殊的。 人们可以期望gcc 4.4.7或OP的环境忽略这一点,我会寻找一个解释。 请看这个临时答案,作为对OP问题的扩展评论。


编辑 :不能重现

系统 :红帽子6

 $ uname -a Linux ysc 2.6.32-504.8.1.el6.x86_64 #1 SMP Wed Jan 28 21:11:36 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux$ 

编译器

 $ g++ --version g++ (GCC) 4.4.7 20120313 (Red Hat 4.4.7-16) 

来源

 $ cat main.cpp #include <iostream> template<typename T> struct trait { static const int value = 0; }; template<> struct trait<char> { static const int value = 1; }; template<> struct trait<signed char> { static const int value = 2; }; template<> struct trait<unsigned char> { static const int value = 3; }; int main() { std::cout << "int:, " << trait<int>::value << "!\n"; std::cout << "char:, " << trait<char>::value << "!\n"; std::cout << "unsigned char:, " << trait<unsigned char>::value << "!\n"; std::cout << "signed char:, " << trait<signed char>::value << "!\n"; } 

汇编

 $ g++ -Wall -Wextra main.cpp 

运行

 $ ./a.out int:, 0! char:, 1! unsigned char:, 3! signed char:, 2! 

它在OP的环境中产生了什么?