Consider the code:
#include <map>
class a {
public:
a();
};
class b {
public:
// implicit default ctor
bool operator<(const b& rhs) const;
private:
a a_val;
};
typedef std::map<b, int> my_map;
void func() {
my_map::value_type x;
}
That compiled correctly with 4.3.2. It fails to compile with pre-4.4 trunk:
Using built-in specs.
Target: i686-linux
Configured with: ../trunk/configure --enable-languages=c,c++ --build=i686-linux
--host=i686-linux --target=i686-linux
--prefix=/g/users/cgd/proj/gcc-trunk/bld/../inst
Thread model: posix
gcc version 4.4.0 20081123 (experimental) (GCC)
with the error:
In file included from
[...]/bin/../lib/gcc/i686-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_algobase.h:71,
from
[...]/bin/../lib/gcc/i686-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_tree.h:67,
from
[...]/bin/../lib/gcc/i686-linux/4.4.0/../../../../include/c++/4.4.0/map:65,
from test2.cc:1:
[...]/bin/../lib/gcc/i686-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_pair.h:
In constructor 'std::pair<_T1, _T2>::pair() [with _T1 = const b, _T2 = int]':
test2.cc:20: instantiated from here
[...]/bin/../lib/gcc/i686-linux/4.4.0/../../../../include/c++/4.4.0/bits/stl_pair.h:84:
error: uninitialized member 'std::pair<const b, int>::first' with 'const' type
'const b'
Looking at the preprocessed source (which i'll attach shortly), I see that
pair's default ctor is:
pair()
: first(), second() { }
I don't know if that's "right," but the C++98 std says that:
"Initializes its members as if implemented: pair() : first(T1()), second(T2())
{}"
(20.2.2, paragraph 2.)
If I change the pair() ctor to be:
pair()
: first(_T1()), second(_T2()) { }
(by hacking the preprocessed source), the result compiles correctly.
(I'm *so* far from an expert on STL that I'm not 100% sure that sample code is
actually valid, but on its face it seems reasonable at least, and 4.3.x
accepted it, and Comeau's test drive accepts it as well.)
--
Summary: 'map' value type + new uninitted const member warnings
causes error
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cgd at google dot com
GCC build triplet: i686-linux
GCC host triplet: i686-linux
GCC target triplet: i686-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38233