re PR c++/46658 (internal compiler error on cp/init.c)

PR c++/46658
	* init.c (build_new_1): Handle value-init in templates differently.

From-SVN: r168655
This commit is contained in:
Jason Merrill 2011-01-11 06:30:07 -05:00 committed by Jason Merrill
parent 41d04a8dfe
commit a67e7daab5
4 changed files with 51 additions and 14 deletions

View File

@ -1,5 +1,8 @@
2011-01-11 Jason Merrill <jason@redhat.com>
PR c++/46658
* init.c (build_new_1): Handle value-init in templates differently.
PR c++/45520
* tree.c (maybe_dummy_object): Check current_class_ref against
context, not current_class_type.

View File

@ -2294,7 +2294,22 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts,
explicit_value_init_p = true;
}
if (array_p)
if (processing_template_decl && explicit_value_init_p)
{
/* build_value_init doesn't work in templates, and we don't need
the initializer anyway since we're going to throw it away and
rebuild it at instantiation time, so just build up a single
constructor call to get any appropriate diagnostics. */
init_expr = cp_build_indirect_ref (data_addr, RO_NULL, complain);
if (TYPE_NEEDS_CONSTRUCTING (elt_type))
init_expr = build_special_member_call (init_expr,
complete_ctor_identifier,
init, elt_type,
LOOKUP_NORMAL,
complain);
stable = stabilize_init (init_expr, &init_preeval_expr);
}
else if (array_p)
{
tree vecinit = NULL_TREE;
if (*init && VEC_length (tree, *init) == 1
@ -2343,8 +2358,7 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts,
{
init_expr = cp_build_indirect_ref (data_addr, RO_NULL, complain);
if (TYPE_NEEDS_CONSTRUCTING (type)
&& (!explicit_value_init_p || processing_template_decl))
if (TYPE_NEEDS_CONSTRUCTING (type) && !explicit_value_init_p)
{
init_expr = build_special_member_call (init_expr,
complete_ctor_identifier,
@ -2354,17 +2368,11 @@ build_new_1 (VEC(tree,gc) **placement, tree type, tree nelts,
}
else if (explicit_value_init_p)
{
if (processing_template_decl)
/* Don't worry about it, we'll handle this properly at
instantiation time. */;
else
{
/* Something like `new int()'. */
tree val = build_value_init (type, complain);
if (val == error_mark_node)
return error_mark_node;
init_expr = build2 (INIT_EXPR, type, init_expr, val);
}
/* Something like `new int()'. */
tree val = build_value_init (type, complain);
if (val == error_mark_node)
return error_mark_node;
init_expr = build2 (INIT_EXPR, type, init_expr, val);
}
else
{

View File

@ -1,5 +1,8 @@
2011-01-11 Jason Merrill <jason@redhat.com>
PR c++/46658
* g++.dg/template/new10.C: New.
PR c++/45520
* g++.dg/cpp0x/lambda/lambda-this3.C: New.

View File

@ -0,0 +1,23 @@
// PR c++/46658
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
template<class T> class scoped_array {
void reset(T * p = 0) { }
};
typedef uint16_t SequenceIndex;
typedef uint32_t SequenceMapIndex;
class Analyzer {
template <typename READER>
bool ReadDictionary( READER& reader );
scoped_array<SequenceIndex> map_from_2_hints_to_composite_sequence;
SequenceMapIndex number_of_composite_sequences;
};
template <typename READER>
bool Analyzer::ReadDictionary( READER &reader )
{
const SequenceMapIndex ntt
= ( number_of_composite_sequences + SequenceMapIndex( 1 ) )
* ( number_of_composite_sequences + 1 );
map_from_2_hints_to_composite_sequence.reset(new SequenceIndex[ntt]());
}