This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/63526] New: O1 O2 O3 optimization and inline template constructor - uninitialized member
- From: "eles.david.88 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 13 Oct 2014 17:01:10 +0000
- Subject: [Bug c++/63526] New: O1 O2 O3 optimization and inline template constructor - uninitialized member
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63526
Bug ID: 63526
Summary: O1 O2 O3 optimization and inline template constructor
- uninitialized member
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: eles.david.88 at gmail dot com
Created attachment 33701
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33701&action=edit
Test case
It seems due to missing zero-initialization in case of inline constructor, I
got a warning for uninitialized value for the following code:
------------- main.cpp ------------------------
#include <iostream>
template <class T>
struct Foo
{
Foo()
{}
void foo()
{std::cout << _foo << std::endl;}
T _foo;
};
int main()
{
Foo<double> f;
f.foo();
return 0;
}
------------------------------------------------
Compilation with "g++ -Wall", the result:
everything is ok.
Compilation with "g++ -Wall -O1", the result:
------------------------------------------------
main.cpp: In function âint main()â:
main.cpp:10:4: warning: âf.Foo<double>::_fooâ is used uninitialized in this
function [-Wuninitialized]
main.cpp:16:15: note: âfâ was declared here
------------------------------------------------
I got a same result with -O2, -O3.
If the constructor is not inline, everything is ok.
It seems that due to optimization the constructor "is inlined", but not in a
prepare way, it "is inlined" without zero-initialization.
Environment information:
--------------------------------------------------
$uname -a
Linux debian 3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 i686 GNU/Linux
$g++ --version
g++ (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---------------------------------------------------
A same behavior can be observed in older releases and distributions:
---------------------------------------------------
$uname -a
Linux rdv 2.6.18-164.6.1.el5 #1 SMP Tue Oct 27 11:28:30 EDT 2009 x86_64 x86_64
x86_64 GNU/Linux
$g++ --version
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---------------------------------------------------
But not in the version:
---------------------------------------------------
$g++ --version
g++ (GCC) 3.4.6 20060404 (Red Hat 3.4.6-4)
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
---------------------------------------------------