8

After (attempting to) upgrade a VS2012 project to use boost 1.57, I can no longer compile--lots and lots of error messages coming out of boost/any_iterator.hpp (see below). As a test, I created a new project that contained nothing but an empty main function and #include "boost/any_iterator.hpp" and got the same set of errors. Here is the code it's complaining about:

// snippet from boost/any_iterator.hpp

template<
            class Value
          , class Traversal
          , class Reference
          , class Difference
          , class Buffer
        >
        class postfix_increment_proxy<
                    range_detail::any_iterator< // line 131
                        Value
                      , Traversal
                      , Reference
                      , Difference
                      , Buffer
                    >
                >
        {
            // ...
        };

There is another class in the same file that follows the same pattern and generates identical errors. range_detail::any_iterator is forward-declared a little higher up in the file:

namespace range_detail
{
   // ...
   template<
                class Value
              , class Traversal
              , class Reference
              , class Difference
              , class Buffer = any_iterator_default_buffer
            >
            class any_iterator;
    // ...
}

For what it's worth, here's the set of errors I get from VS2012:

Error   1   error C2143: syntax error : missing ';' before '<'  [path]\boost\range\detail\any_iterator.hpp  131
Error   2   error C2059: syntax error : '<' [path]\boost\range\detail\any_iterator.hpp  131
Error   3   error C2065: 'Value' : undeclared identifier    [path]\boost\range\detail\any_iterator.hpp  134
Error   4   error C2065: 'Traversal' : undeclared identifier    [path]\boost\range\detail\any_iterator.hpp  135
Error   5   error C2065: 'Reference' : undeclared identifier    [path]\boost\range\detail\any_iterator.hpp  136
Error   6   error C2065: 'Difference' : undeclared identifier   [path]\boost\range\detail\any_iterator.hpp  137
Error   7   error C2065: 'Buffer' : undeclared identifier   [path]\boost\range\detail\any_iterator.hpp  138
Error   8   error C2923: 'boost::range_detail::any_iterator' : 'Value' is not a valid template type argument for parameter 'Value'  [path]\boost\range\detail\any_iterator.hpp  138
Error   9   error C2923: 'boost::range_detail::any_iterator' : 'Traversal' is not a valid template type argument for parameter 'Traversal'  [path]\boost\range\detail\any_iterator.hpp  138
Error   10  error C2923: 'boost::range_detail::any_iterator' : 'Reference' is not a valid template type argument for parameter 'Reference'  [path]\boost\range\detail\any_iterator.hpp  138
Error   11  error C2923: 'boost::range_detail::any_iterator' : 'Difference' is not a valid template type argument for parameter 'Difference'    [path]\boost\range\detail\any_iterator.hpp  138
Error   12  error C2923: 'boost::range_detail::any_iterator' : 'Buffer' is not a valid template type argument for parameter 'Buffer'    [path]\boost\range\detail\any_iterator.hpp  138
Error   13  error C2143: syntax error : missing ';' before '{'  [path]\boost\range\detail\any_iterator.hpp  140
Error   14  error C2447: '{' : missing function header (old-style formal list?) [path]\boost\range\detail\any_iterator.hpp  140

Is anyone aware of a workaround?

dlf
  • 9,045
  • 4
  • 32
  • 58
  • That's just a partial specialization of `postfix_increment_proxy` for `T` is any `any_iterator` type. It just looks complicated because `any_iterator` is templated on 5 things and you have to reproduce all of them to do the specialization - but that part of the code looks totally fine. I have no idea why it doesn't compile tho. – Barry Nov 05 '14 at 14:46
  • @Barry Got it; I missed that iterator_facade.hpp had previously declared `template postix_increment_proxy`, so I couldn't figure out where that `T` was coming from. (question edited) – dlf Nov 05 '14 at 14:52
  • And that actually looks like it might have led me to the answer--`postfix_increment_proxy` is in the `boost::iterators::detail` namespace, but its usage in `any_iterator.hpp` (whose classes are not in that namespace) is unqualified. – dlf Nov 05 '14 at 14:58
  • Glad I could help you figure out how to solve it pretty much completely by yourself :) – Barry Nov 05 '14 at 15:04

1 Answers1

10

This appears to be a bug in the boost codebase. postfix_increment_proxy and writable_postfix_increment_proxy are both in the boost::iterators::detail namespace (iterator_facade.hpp). However, both names are used unqualified in any_iterator.hpp. Adding boost::iterators::detail:: in front of both names allows the code to compile.

For anyone who's uncomfortable with the idea of editing boost code, including iterator_facade.hpp followed by using namespace boost::iterators::detail followed by an include for any_iterator.hpp will also solve the problem at the cost of namespace pollution. VS2012 doesn't support them so it doesn't do me any good, but you could presumably use a C++11 using too.

Ticket submitted: https://svn.boost.org/trac/boost/ticket/10754

dlf
  • 9,045
  • 4
  • 32
  • 58
  • 1
    I think the described workaround is not accurate. It might be working for MSVC but only due to broken specialization logic then. The fix is to specialize the classes inside namespace `boost::iterators::detail` instead of `boost::detail` – sehe Dec 24 '14 at 22:48