Boost logo

Boost :

Subject: Re: [boost] [mpl] Problem with VC++14 and boost::mpl::size_t
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2015-07-26 10:34:22


On 26.07.2015 17:20, Edward Diener wrote:
> On 7/25/2015 2:48 AM, Matt Calabrese wrote:
>> On Fri, Jul 24, 2015 at 7:41 PM, Edward Diener <eldiener_at_[hidden]>
>> wrote:
>>
>>> pointing to the line after it encounters 'struct size_t' as far as I can
>>> make out ( you need to preprocess the size_t.cpp test, comment out the
>>> #line directives and run the test against the preprocessed result to see
>>> what the compiler is objecting to ). It therefore fails a number of mpl
>>> tests which all prior versions of VC++ pass.
>>>
>>> It flags this error in 5 mpl tests which use the boost::mpl::size_t
>>> integral wrapper, among which the easiest to analyze is the
>>> size_t.cpp test
>>> itself.
>>>
>>> Anybody have any idea what is going on here with the compiler, or
>>> whether
>>> it can be fixed somehow in VC++14 for the mpl code ?
>>>
>>
>> I don't have the compiler, but my guess is it's probably actually
>> confused
>> on the line:
>>
>> typedef size_t type;
>>
>> A simple workaround to try could be to change the typedef to:
>>
>> typedef mpl::size_t<N> type;
>>
>> If that fix works, I'd be surprised if such a change would break any
>> other
>> compilers. This is all just a guess, though.
>>
>
> My latest investigation, using the mpl::size_t code directly in a test,
> shows that:
>
> // size_t_bug.cpp
>
> #include <cstddef>
> namespace boost { namespace mpl {
> struct integral_c_tag { static const int value = 0; };
> template< std::size_t N >
> struct size_t
> {
> static const std::size_t value = N;
> typedef size_t type;
> typedef std::size_t value_type;
> typedef integral_c_tag tag;
> typedef boost::mpl::size_t< static_cast<std::size_t>((value + 1)) >
> next;
> typedef boost::mpl::size_t< static_cast<std::size_t>((value - 1)) >
> prior;
> operator std::size_t() const { return
> static_cast<std::size_t>(this->value); }
> };
> template< std::size_t N >
> std::size_t const boost::mpl::size_t< N >::value;
> }}
>
> #include <boost/core/lightweight_test.hpp>
> int main()
> {
> return 0;
> }
> using namespace boost;
> using namespace mpl;
>
> fails under VC++14 with:
>
> size_t_bug.cpp(26): error C2872: 'size_t': ambiguous symbol
> predefined C++ types (compiler internal)(16): note: could be 'unsigned
> int size_t'
> size_t_bug.cpp(6): note: or 'boost::mpl::size_t'
>
> but if I comment out the include of lightweight test or if I comment out
> the using directive, the source compiles without error. How using
> directives which occur after all code can affect the compilation is
> beyond me.
>
> Anybody who would like to pitch in and try to determine what is causing
> VC++14 to fail with the above code, which is essentially why it is
> failing with the MPL tests involving boost::mpl::size_t, please feel
> free to do so.
>
> Needless to say VC++12 and below, as well as gcc and clang, compile the
> test without error.

This is obviously a compiler bug. Could you report it to MS Connect?

If you're still interested in experimenting, you could try reducing it
further by, e.g. replacing lightweight_test.hpp with bits of code from
it, starting from just header includes from lightweight_test.hpp.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk