Boost logo

Boost :

Subject: Re: [boost] [utility/swap] MSVC 10 test failure, unsigned long to std::bitset conversion invalid?
From: Niels Dekker - address until 2010-10-10 (niels_address_until_2010-10-10_at_[hidden])
Date: 2010-03-07 11:40:48


>> Note that C++0x also adds the bitset(const char*) constructor.
>> As proposed by LWG issue #778, by Thorsten Ottosen:
>> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3019.html#778

On 2010-03-07 14:51, Bo Persson wrote:
> And it says that the effect should be as if constructed by
> bitset(string(str)). This makes it illegal to use a null pointer,
> like 0, as this is not allowed for std::string.

Well, the bitset(const char*) constructor was never intended to be
called when doing std::bitset<5> bits(0); And in C++98/C++03, such an
initialization will call the bitset(unsigned long) constructor, which is
entirely legal.

>>> The int constructor looks like an MS special that was added in the
>>> release candidate. I was wondering if it was added to help out
>>> with this other bug:
>>> https://connect.microsoft.com/VisualStudio/feedback/details/500122/bitset-5-bits-0-fails-with-conflict-between-longlong-and-char

> Which then isn't a bug at all, but explicitly disallowed by the
> standard [lib.string.cons].

Microsoft added the bitset(int) constructor, in order to preserve C++98
backward compatibility, when a user has set all bits to zero by doing
std::bitset<N>(0). Which is nice. (And the C++ Standard allows an
implementation some freedom to add extra member function overloads,
according to the section "Member functions", [member.functions].) But
unfortunately, by doing so, MSVC broke another C++98 use case,
initializing an std::bitset<N> by an unsigned long. Which is what
boost/libs/utility/swap/test/std_bitset.cpp does.

Thanks for your feedback,

Kind regards,

   Niels

-- 
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center

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