Re: uninitialized string

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

 





On 1/21/2019 6:39 PM, Jonathan Wakely wrote:
On Mon, 21 Jan 2019 at 17:29, Manfred <mx2927@xxxxxxxxx> wrote:
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.

But it is the point. For std::string all GCC sees is a call to a
constructor...
[...]

Because there's no constructor for int, but there's a constructor for
std::string.

Thanks for the explanation.



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.

That's for C, not C++, and so isn't relevant here (the warning you get
for int comes from -Winit-self which is only for C++).

(Actually the output for int is:
selfint.cc: In function ‘int main()’:
selfint.cc:5:7: warning: ‘n’ is used uninitialized in this function
[-Wuninitialized]
    int n { n };

Which says -Wuninitialized)


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52167 is exactly your case.

There are several related bugs like
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=48483 which apply to use
of uninitialized values inside constructors.


Thanks for the bug list too. I see there are quite a few that are open (unlike the one I mentioned that was rejected).



[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