我在proto.h的第42行添加了以下内容:
typedef boost::make_unsigned<off_t>::type uoff_t;
现在我从gcc那里得到了这个冗长而混乱的警告抱怨将枚举与同一个枚举类型进行比较:
In file included from proto.cpp:12:
/usr/local/include/boost/type_traits/is_unsigned.hpp: In instantiation of 'boost::detail::is_ununsigned_helper<long int>':
/usr/local/include/boost/type_traits/is_unsigned.hpp:73: instantiated from 'boost::detail::is_unsigned_imp<long int>'
/usr/local/include/boost/type_traits/is_unsigned.hpp:123: instantiated from 'boost::is_unsigned<long int>'
/usr/local/include/boost/type_traits/make_unsigned.hpp:110: instantiated from 'boost::detail::make_unsigned_imp<long int>'
/usr/local/include/boost/type_traits/make_unsigned.hpp:130: instantiated from 'boost::make_unsigned<long int>'
proto.h:42: instantiated from here
/usr/local/include/boost/type_traits/is_unsigned.hpp:40: warning: comparison between 'enum boost::detail::is_unsigned_values<long int>::<anonymous>' and 'enum boost::detail::is_unsigned_values<long int>::<anonymous>'
有人可以解读这个吗?
答案 0 :(得分:3)
这就是发生的事情
BOOST_NO_INCLASS_MEMBER_INITIALIZATION
在Boost.Config中得到定义(不知道为什么它会用于gcc,但我暂时不会这样做)。因此,
BOOST_STATIC_CONSTANT(no_cv_t, minus_one = (static_cast<no_cv_t>(-1)));
BOOST_STATIC_CONSTANT(no_cv_t, zero = (static_cast<no_cv_t>(0)));
<{1}}中的声明扩展为
boost::detail::is_unsigned_values
然后在enum { minus_one = (static_cast<no_cv_t>(-1)) };
enum { zero = (static_cast<no_cv_t>(0)) };
中比较这两个未命名但不同枚举的枚举数。因此,如果boost::detail::is_ununsigned_helper
扩展为BOOST_STATIC_CONSTANT()
,则不会发生警告。
还有两个问题需要回答:
- &GT;为什么在您的案例中定义static const no_cv_t blah blah...
?
- &GT;如果确定了该宏,则可以生成这样的警告(比较不同枚举的枚举器)。它在这里是无害的,但在Boost中被阻止可能会很好。这值得吗?
注意:我使用Boost 1.43的代码作为参考。