From ad1063d5454b3d745bea35909dc677344250d827 Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Fri, 3 Dec 2004 09:51:39 +0000 Subject: re PR c++/18318 (ICE: error: Multiple inline callers) cp: PR c++/18318 * parser.c (cp_parser_new_type_id): Move array size expression checks from here ... * init.c (build_new): ... to here. testsuite: PR c++/18318 * g++.dg/template/new1.C: New. From-SVN: r91678 --- gcc/cp/ChangeLog | 10 +++++++- gcc/cp/init.c | 9 ++++++++ gcc/cp/parser.c | 10 +------- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/template/new1.C | 45 ++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/new1.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index dc158b0..5ac6cd7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,12 @@ 2004-12-02 Nathan Sidwell + PR c++/18318 + * parser.c (cp_parser_new_type_id): Move array size expression + checks from here ... + * init.c (build_new): ... to here. + +2004-12-02 Nathan Sidwell + PR c++/18758 * parser.c (cp_parser_class_head): Return NULL_TREE when push_template_decl fails. Update comment. @@ -18,7 +25,8 @@ 2004-12-01 Matt Austern - * name-lookup.c (namespace_binding): Omit alias check for global namespace. + * name-lookup.c (namespace_binding): Omit alias check for global + namespace. 2004-12-01 Nathan Sidwell diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 9d00d4b..7dd15d2 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1633,6 +1633,15 @@ build_new (tree placement, tree type, tree nelts, tree init, return rval; } + if (nelts) + { + if (!build_expr_type_conversion (WANT_INT | WANT_ENUM, nelts, false)) + pedwarn ("size in array new must have integral type"); + nelts = save_expr (cp_convert (sizetype, nelts)); + if (nelts == integer_zero_node) + warning ("zero size array reserves no space"); + } + /* ``A reference cannot be created by the new operator. A reference is not an object (8.2.2, 8.4.3), so a pointer to it could not be returned by new.'' ARM 5.3.3 */ diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index cf96406..46b9385 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -4901,15 +4901,7 @@ cp_parser_new_type_id (cp_parser* parser, tree *nelts) *nelts = declarator->u.array.bounds; if (*nelts == error_mark_node) *nelts = integer_one_node; - else if (!processing_template_decl) - { - if (!build_expr_type_conversion (WANT_INT | WANT_ENUM, *nelts, - false)) - pedwarn ("size in array new must have integral type"); - *nelts = save_expr (cp_convert (sizetype, *nelts)); - if (*nelts == integer_zero_node) - warning ("zero size array reserves no space"); - } + if (outer_declarator) outer_declarator->declarator = declarator->declarator; else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5c89941..a24a39e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2004-12-03 Nathan Sidwell + + PR c++/18318 + * g++.dg/template/new1.C: New. + 2004-12-02 Tobias Schlueter PR fortran/18710 diff --git a/gcc/testsuite/g++.dg/template/new1.C b/gcc/testsuite/g++.dg/template/new1.C new file mode 100644 index 0000000..63ee2f9 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/new1.C @@ -0,0 +1,45 @@ +// { dg-do run } +// { dg-options "-O2" } + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Nathan Sidwell 2 Dec 2004 + +// PR 18318. ICE with template new[] +// Origin:Elliot Hughes +// Andrew Pinski + +struct Aint +{ + ~Aint (); + Aint (); +}; + +Aint::Aint () {} +Aint::~Aint () {} + +static int count; + +template +struct A +{ + unsigned Blksize() const; + + void f() + { + new T[Blksize()]; + } +}; + +template unsigned A::Blksize () const +{ + count++; + return 1; +} + +int main () +{ + A a; + a.f(); + + return count != 1; +} -- cgit v1.1