Re: error: value-initialization of reference
On Sep 10, 9:58 pm, David Hammarwall <david.hammarw...@gmail.com>
wrote:
Hi,
I've got a problem using a library where I get the compiler error
"value-initialization of reference" (using gcc4.3.2).
I do now think, more than ever, that this is a bug in how gcc-4.3.2
is handling value-initialization. (Something very similar was
reported on the gcc mailing list as a regression in 4.4 -
http://gcc.gnu.org/ml/gcc-bugs/2008-11/msg01948.html.)
If we pare your example right down to:
int i = 0;
struct A {
int& i_ref;
A() : i_ref(i) { }
};
struct B {
//B() { }
A a;
};
int main()
{
A(); //#1
B(); //#2
return 0;
}
gcc-4.3.2 produces the same error on line #2 but *not* on #1, despite
the fact that in both instances it should be performing value-
initialization to form an instance of A, in the failed case (#2),
recursively from the initialization of B(). (#1 value-initializes an
instance of A; #2 value-initializes an instance of B which, without
a user-declared default constructor, should propagate the value-
initialization to its members and thus value-initialize an instance
of A (B().a).) In both, the value-initialization of the A instance
/should/ invoke the user-declared default constructor for that class
(on my interpretation of 8.3 [dcl.init]).
What gcc is not doing in the recursive application of value-
initialization down to B().a is 'adjusting' the /meaning/ of value-
initialization based on the fact that A is a "non-union class type
*with* a user-declared default constructor."
It's as if the compiler is saying "Hhm, B doesn't have a user-
defined default constructor, so let's just forget /all/ about
udef-def-ctors from now on. Keep going!"
Regards
Paul Bibbings
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]