[Bug c++/101850] Initialising a struct/class variable to itself does not fail at compile time (but throws std::bad_alloc at run time, as expected)
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Tue Aug 10 20:00:27 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101850
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Target Milestone|--- |11.0
Status|UNCONFIRMED |RESOLVED
--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
extern "C" char* strdup(const char*);
extern "C" void free(void*);
namespace std
{
struct string
{
string() { }
string(string const& s) : data(strdup(s.data)) { }
string& operator=(string const& s) {
free(data);
strdup(s.data);
return *this;
}
~string() { free(data); }
char* data = nullptr;
};
}
class M {
std::string s;
public:
M(std::string t) : s(t) {}
};
int main() {
M m = m;
}
This started to warn with r11-959 "Implement a solution for PR middle-end/10138
and PR middle-end/95136."
I think this can be considered FIXED for GCC 11.
More information about the Gcc-bugs
mailing list