Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

The following code, written as a minimal problematic example, fails to compile:

#include <boost/serialization/strong_typedef.hpp>

BOOST_STRONG_TYPEDEF( void * const *, my_const_iterator )
int main() {
    return 0;
}

Compiler is:

GNU g++

Compiler flags are:

-Wall -Wextra -Werror -std=c++11 -pedantic

Compiler errors are:

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 )
 ^

So the compiler seems to be saying that the problem is converting void * const * const to void * const *, but this code compiles just fine (ignoring the warning that b is unused), as it seems to me that it should:

int main() {
    void * const * const a( nullptr );
    void * const * b( a );
    return 0;
}

I think I must be missing something silly. Why won't the BOOST_STRONG_TYPEDEF compile?

share|improve this question
1  
Your code comment puzzles me. Why not just omit the arguments or cast them to void if you don’t want the warning? Both are simpler than your odd code + comment. –  Konrad Rudolph Jun 9 '13 at 22:53
1  
@KonradRudolph I simplified the example as suggested and also removed one of the typedefs so that it is truly a 'minimal problematic example' now. Thanks. –  Ryan N. Lichtenwalter Jun 10 '13 at 1:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.