re PR c++/38427 (crash for reference init code)

PR c++/38427
	* init.c (perform_member_init): For value-initialized
	references call permerror instead of warning and don't emit any
	INIT_EXPR.

	* g++.dg/init/ctor9.C: New test.

From-SVN: r142818
This commit is contained in:
Jakub Jelinek 2008-12-18 21:51:07 +01:00 committed by Jakub Jelinek
parent baafc53472
commit 0f737a30c0
4 changed files with 35 additions and 9 deletions

View File

@ -1,3 +1,10 @@
2008-12-18 Jakub Jelinek <jakub@redhat.com>
PR c++/38427
* init.c (perform_member_init): For value-initialized
references call permerror instead of warning and don't emit any
INIT_EXPR.
2008-12-18 Jason Merrill <jason@redhat.com>
PR c++/38485

View File

@ -435,19 +435,25 @@ perform_member_init (tree member, tree init)
{
/* mem() means value-initialization. */
if (TREE_CODE (type) == ARRAY_TYPE)
init = build_vec_init (decl, NULL_TREE, NULL_TREE,
/*explicit_value_init_p=*/true,
/* from_array=*/0,
tf_warning_or_error);
{
init = build_vec_init (decl, NULL_TREE, NULL_TREE,
/*explicit_value_init_p=*/true,
/* from_array=*/0,
tf_warning_or_error);
finish_expr_stmt (init);
}
else
{
if (TREE_CODE (type) == REFERENCE_TYPE)
warning (0, "%Jdefault-initialization of %q#D, "
"which has reference type",
current_function_decl, member);
init = build2 (INIT_EXPR, type, decl, build_value_init (type));
permerror (input_location, "%Jvalue-initialization of %q#D, "
"which has reference type",
current_function_decl, member);
else
{
init = build2 (INIT_EXPR, type, decl, build_value_init (type));
finish_expr_stmt (init);
}
}
finish_expr_stmt (init);
}
/* Deal with this here, as we will get confused if we try to call the
assignment op for an anonymous union. This can happen in a

View File

@ -1,3 +1,8 @@
2008-12-18 Jakub Jelinek <jakub@redhat.com>
PR c++/38427
* g++.dg/init/ctor9.C: New test.
2008-12-18 Jason Merrill <jason@redhat.com>
PR c++/38485

View File

@ -0,0 +1,8 @@
// PR c++/38427
// { dg-do compile }
struct S
{
int &ref;
S() : ref() {}; // { dg-error "value-initialization of" }
};