以下代码作为一个问题最小的示例编写,无法编译:
#include <boost/serialization/strong_typedef.hpp>
BOOST_STRONG_TYPEDEF( void * const *, my_const_iterator )
int main() {
return 0;
}
编译器是:
GNU g++
编译器标志是:
-Wall -Wextra -Werror -std=c++11 -pedantic
编译器错误是:
In file included from main.cpp:1:0:
main.cpp: In constructor 'my_const_iterator::my_const_iterator(const void* const*)':
../boost_1_53_0/boost/serialization/strong_typedef.hpp:36:38: error: invalid conversion from 'const void* const*' to 'void* const*' [-fpermissive]
explicit D(const T t_) : t(t_) {}; \
^
main.cpp:3:1: note: in expansion of macro 'BOOST_STRONG_TYPEDEF'
BOOST_STRONG_TYPEDEF( void * const *, my_const_iterator )
^
main.cpp: In member function 'my_const_iterator& my_const_iterator::operator=(const void* const*&)':
../boost_1_53_0/boost/serialization/strong_typedef.hpp:40:42: error: invalid conversion from 'const void* const*' to 'void* const*' [-fpermissive]
D & operator=(const T & rhs) { t = rhs; return *this;} \
^
main.cpp:3:1: note: in expansion of macro 'BOOST_STRONG_TYPEDEF'
BOOST_STRONG_TYPEDEF( void * const *, my_const_iterator )
^
main.cpp: In member function 'my_const_iterator::operator const void* const*&() const':
../boost_1_53_0/boost/serialization/strong_typedef.hpp:41:45: error: invalid initialization of reference of type 'const void* const*&' from expression of type 'void* const* const'
operator const T & () const {return t; } \
^
main.cpp:3:1: note: in expansion of macro 'BOOST_STRONG_TYPEDEF'
BOOST_STRONG_TYPEDEF( void * const *, my_const_iterator )
^
所以编译器似乎在说问题正在转换void * const * const
为void * const *
,但是这段代码编译得很好(忽略 b 未使用的警告),因为在我看来它应该:
int main() {
void * const * const a( nullptr );
void * const * b( a );
return 0;
}
我想我一定错过了一些愚蠢的事情。为什么 BOOST_STRONG_TYPEDEF 不能编译?