From 70ec16f7c29de16e0ec824de9a8979ff0a902488 Mon Sep 17 00:00:00 2001 From: Andrew Pinski Date: Sun, 29 Apr 2007 06:22:14 +0000 Subject: re PR c++/30221 (internal compiler error: in reshape_init_r, at cp/decl.c:4632) 2007-04-28 Andrew Pinski PR C++/30221 * decl.c (reshape_init_r): Don't reshape the first element if it is a pointer to member function. 2007-04-28 Andrew Pinski PR C++/30221 * g++.dg/init/ptrfn2.C: New test. * g++.dg/init/ptrfn3.C: New test. From-SVN: r124271 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/decl.c | 11 ++++++++--- gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/init/ptrfn2.C | 14 ++++++++++++++ gcc/testsuite/g++.dg/init/ptrfn3.C | 14 ++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/ptrfn2.C create mode 100644 gcc/testsuite/g++.dg/init/ptrfn3.C (limited to 'gcc') diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 11f1396..2a363c4 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2007-04-28 Andrew Pinski + + PR C++/30221 + * decl.c (reshape_init_r): Don't reshape the first element if it + is a pointer to member function. + 2007-04-27 Simon Baldwin * decl.c (grokparms): Changed message format from %qD to %qE. diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index e75f4fc..31bc8d2 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4638,19 +4638,24 @@ reshape_init_r (tree type, reshape_iter *d, bool first_initializer_p) { if (TREE_CODE (init) == CONSTRUCTOR) { + if (TREE_TYPE (init) && TYPE_PTRMEMFUNC_P (TREE_TYPE (init))) + /* There is no need to reshape pointer-to-member function + initializers, as they are always constructed correctly + by the front end. */ + ; + else if (COMPOUND_LITERAL_P (init)) /* For a nested compound literal, there is no need to reshape since brace elision is not allowed. Even if we decided to allow it, we should add a call to reshape_init in finish_compound_literal, before calling digest_init, so changing this code would still not be necessary. */ - if (!COMPOUND_LITERAL_P (init)) + gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (init)); + else { ++d->cur; gcc_assert (BRACE_ENCLOSED_INITIALIZER_P (init)); return reshape_init (type, init); } - else - gcc_assert (!BRACE_ENCLOSED_INITIALIZER_P (init)); } warning (OPT_Wmissing_braces, "missing braces around initializer for %qT", diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c064f17..3113b30 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2007-04-28 Andrew Pinski + + PR C++/30221 + * g++.dg/init/ptrfn2.C: New test. + * g++.dg/init/ptrfn3.C: New test. + 2007-04-29 Paul Thomas PR fortran/31711 diff --git a/gcc/testsuite/g++.dg/init/ptrfn2.C b/gcc/testsuite/g++.dg/init/ptrfn2.C new file mode 100644 index 0000000..0ca922b --- /dev/null +++ b/gcc/testsuite/g++.dg/init/ptrfn2.C @@ -0,0 +1,14 @@ +// { dg-options "" } +// { dg-do compile } +// C++/30221 +// We would ICE while trying to reshape the pointer to +// member function element which is not needed. + + +class abstract {}; +typedef void (abstract::*fptr1) (short & s ) const; +struct s {}; +s array[] = +{ + (fptr1)0 +};// { dg-error "" } diff --git a/gcc/testsuite/g++.dg/init/ptrfn3.C b/gcc/testsuite/g++.dg/init/ptrfn3.C new file mode 100644 index 0000000..9600850 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/ptrfn3.C @@ -0,0 +1,14 @@ +// { dg-options "" } +// { dg-do compile } +// C++/30221 +// We would ICE while trying to reshape the pointer to +// member function element which is not needed. + + +class abstract {}; +typedef void (abstract::*fptr1) (short & s ) const; +struct s {fptr1 f;}; +s array[] = +{ + (fptr1)0 +}; -- cgit v1.1