https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66485
Bug ID: 66485
Summary: std::string single-character assignment operator
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: yurivkhan at gmail dot com
Target Milestone: ---
gcc’s implementation of std::basic_string contains a non-standard and very
surprising operator= which accepts a single character or anything that is
implicitly castable thereto.
To reproduce:
===
#include <iostream>
#include <string>
int main()
{
std::string s;
s = 42;
std::cout << s << "\n";
}
===
$ g++ --version
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2[…]
$ g++ test.cpp
(with any of -std= variations, with or without -Wall -pedantic)
Observed behavior: compiles, runs, outputs a single character * (asterisk).
Expected behavior: compilation error, because the standard does not define any
such operator=.