'void * const *'的BOOST_STRONG_TYPEDEF将无法编译

时间:2013-06-09 22:41:31

标签: boost const

以下代码编写为最小问题的示例,无法编译:

#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不能编译?

0 个答案:

没有答案