Re: uninitialized string

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 1/21/2019 6:18 PM, Jonathan Wakely wrote:
On Mon, 21 Jan 2019 at 17:13, Manfred <mx2927@xxxxxxxxx> wrote:

[...]

I wonder why int triggers the warning, but std::string does not.

Well for starters, std::string is not the same as int, not even close.

I know, they obviously are very different objects, but that's not the point.


It's pretty obvious when you think about it. Constructing a
std::string calls a constructor, in this case, it calls the
basic_string(const basic_string&) constructor, and passes the *this as
the argument, which makes a copy of the string. The problem is that
the string was never constructed, so it's a copy of garbage.

That's it, the object is used before it is initialized.
Apparently gcc is able to catch this with int (probably other types too), but not with string.


Failing to warn about it is a longstanding and well-known defect in
GCC, you can find lots of discussion in bugzilla.

The following was reported:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71228

Since this complains about int, but apparently int works today, I was wondering if anything is going on about string a well.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux