This page is a snapshot from the LWG issues list, see theLibrary Active Issues List for more information and the meaning ofC++11 status.
bitsetSection: 22.9.2.2[bitset.cons]Status:C++11Submitter: Christopher JeffersonOpened: 2010-03-07Last modified: 2016-01-28
Priority:Not Prioritized
View all otherissues in [bitset.cons].
View all issues withC++11 status.
Discussion:
As mentioned on the boost mailing list:
The following code, valid in C++03, is broken in C++0x due to ambiguitybetween the "unsigned long long" and "char*"constructors.
#include <bitset>std::bitset<10> b(0);
[The proposed resolution has been reviewed by Stephan T. Lavavej.]
[Post-Rapperswil]
The proposed resolution has two problems:
it fails to provide support for non-terminated strings, whichcould be easily added and constitutes an important use-case. Forexample, the following code would invoke UB with the currentP/R:
char s[4] = { '0', '1', '0', '1' }; // notice: not null-terminated!bitset<4> b(s, 0, 4);because it requires the evaluation (under the as-if rule, to be fair,but it doesn't matter) ofbasic_string<char>(s)it promotes a consistency between the twobitsetconstructors that take aconst std::string& and aconst char*, respectively, while practice established bystd::basic_string would recommend a different set ofparameters. In particular, the constructor ofstd::basic_string that takes aconst char* doesnot have apos parameter
Moved to Tentatively Ready with revised wording provided by Alberto Ganesh Babati after 5 positive votes on c++std-lib.
[Adopted at 2010-11 Batavia]
Proposed resolution:
<bitset> in22.9.2[template.bitset]/1, replace the fourth bitset constructor:explicit bitset(const char *str);template <class charT> explicit bitset( const charT *str, typename basic_string<charT>::size_type n = basic_string<charT>::npos, charT zero = charT('0'), charT one = charT('1'));
explicit bitset(const char *str);template <class charT>explicitbitset(const charT *str, typename basic_string<charT>::size_type n = basic_string<charT>::npos, charT zero = charT('0'), charT one = charT('1'));
Effects: Constructs an object of classbitset<N> as if bybitset(string(str)).
bitset( n == basic_string<charT>::npos ? basic_string<charT>(str) : basic_string<charT>(str, n), 0, n, zero, one)