Bug 61658 - Invalid std::string(size_type, value_type) constructor implementation
Summary: Invalid std::string(size_type, value_type) constructor implementation
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-30 12:47 UTC by __vic
Modified: 2014-06-30 13:38 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description __vic 2014-06-30 12:47:34 UTC
#include<string>
#include<iostream>

int main()
{
    std::string st{1U, '0'};
    std::cout << st.length() << '\n';
    std::cout << st << '\n';
}

Prints:
2
☺0


Must be:
1
0
Comment 1 __vic 2014-06-30 12:54:05 UTC
If replace with:

std::string st(1U, '0');

then prints as expected:
1
0

Why {1U, '0'} is treated as std::initializer_list<char> ?
Comment 2 Jonathan Wakely 2014-06-30 13:38:44 UTC
Because the standard says so