[Bug 1284973] [NEW] std::array does not 0-initialise its members (per standard)
Volodya
volodya at whengendarmesleeps.org
Wed Feb 26 05:01:26 UTC 2014
Public bug reported:
Compiling the following example code:
#include <iostream>
#include <array>
int main(int argc, char* argv[])
{
char a1[10];
std::array<char, 10> a2;
for(int i=0; i<10; i++)
{
std::cout << "a1[" << i << "] = " << (int)a1[i] << std::endl;
}
for(int i=0; i<10; i++)
{
std::cout << "a2[" << i << "] = " << (int)a2[i] << std::endl;
}
}
compiling with:
g++ -std=c++11 arrays.cpp
produces the following:
$ ./a.out
a1[0] = -36
a1[1] = -101
a1[2] = -13
a1[3] = -65
a1[4] = 85
a1[5] = -118
a1[6] = 70
a1[7] = -73
a1[8] = -16
a1[9] = -43
a2[0] = 113
a2[1] = -73
a2[2] = 0
a2[3] = 0
a2[4] = 0
a2[5] = 0
a2[6] = -37
a2[7] = -119
a2[8] = 4
a2[9] = 8
Somehow at least some of the members of std::array retain their non-zero values, which goes against C++11 standard.
Interesting to note that four values do get zero-filled (regardless of
the size of the array) on a reasonably large array, but not others. It
may, of course, but just a lucky fluke.
ProblemType: Bug
DistroRelease: Ubuntu 13.10
Package: g++ 4:4.8.1-2ubuntu3
ProcVersionSignature: Ubuntu 3.11.0-17.31-generic 3.11.10.3
Uname: Linux 3.11.0-17-generic i686
ApportVersion: 2.12.5-0ubuntu2.2
Architecture: i386
Date: Wed Feb 26 08:48:34 2014
InstallationDate: Installed on 2013-12-22 (65 days ago)
InstallationMedia: Ubuntu 13.10 "Saucy Salamander" - Release i386 (20131016.1)
MarkForUpload: True
SourcePackage: gcc-defaults
UpgradeStatus: No upgrade log present (probably fresh install)
** Affects: gcc-defaults (Ubuntu)
Importance: Undecided
Status: New
** Tags: apport-bug i386 saucy
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-defaults in Ubuntu.
https://bugs.launchpad.net/bugs/1284973
Title:
std::array does not 0-initialise its members (per standard)
Status in “gcc-defaults” package in Ubuntu:
New
Bug description:
Compiling the following example code:
#include <iostream>
#include <array>
int main(int argc, char* argv[])
{
char a1[10];
std::array<char, 10> a2;
for(int i=0; i<10; i++)
{
std::cout << "a1[" << i << "] = " << (int)a1[i] << std::endl;
}
for(int i=0; i<10; i++)
{
std::cout << "a2[" << i << "] = " << (int)a2[i] << std::endl;
}
}
compiling with:
g++ -std=c++11 arrays.cpp
produces the following:
$ ./a.out
a1[0] = -36
a1[1] = -101
a1[2] = -13
a1[3] = -65
a1[4] = 85
a1[5] = -118
a1[6] = 70
a1[7] = -73
a1[8] = -16
a1[9] = -43
a2[0] = 113
a2[1] = -73
a2[2] = 0
a2[3] = 0
a2[4] = 0
a2[5] = 0
a2[6] = -37
a2[7] = -119
a2[8] = 4
a2[9] = 8
Somehow at least some of the members of std::array retain their non-zero values, which goes against C++11 standard.
Interesting to note that four values do get zero-filled (regardless of
the size of the array) on a reasonably large array, but not others. It
may, of course, but just a lucky fluke.
ProblemType: Bug
DistroRelease: Ubuntu 13.10
Package: g++ 4:4.8.1-2ubuntu3
ProcVersionSignature: Ubuntu 3.11.0-17.31-generic 3.11.10.3
Uname: Linux 3.11.0-17-generic i686
ApportVersion: 2.12.5-0ubuntu2.2
Architecture: i386
Date: Wed Feb 26 08:48:34 2014
InstallationDate: Installed on 2013-12-22 (65 days ago)
InstallationMedia: Ubuntu 13.10 "Saucy Salamander" - Release i386 (20131016.1)
MarkForUpload: True
SourcePackage: gcc-defaults
UpgradeStatus: No upgrade log present (probably fresh install)
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1284973/+subscriptions
More information about the foundations-bugs
mailing list