From 8ab079f4d53b0a5ec861b81635e105ae4677255f Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Fri, 23 Oct 2009 21:38:50 +0000 Subject: [PATCH] re PR c++/40808 (member template specialization causes ICE) Fix for PR c++/40808 gcc/cp/ChangeLog: PR c++/40808 * mangle.c (write_template_args): Allow mangling of empty template argument list. Updated function comments. gcc/testsuite/ChangeLog: PR c++/40808 * g++.dg/abi/mangle34.C: New test From-SVN: r153517 --- gcc/cp/ChangeLog | 6 +++++ gcc/cp/mangle.c | 9 ++++--- gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/g++.dg/abi/mangle34.C | 41 +++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/abi/mangle34.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 70cdad390f9..3ce735b3fe9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-10-23 Dodji Seketeli + + PR c++/40808 + * mangle.c (write_template_args): Allow mangling of empty template + argument list. Updated function comments. + 2009-10-23 Jason Merrill * semantics.c (lambda_expr_this_capture): Use thisify_lambda_field. diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index f9a550394d6..d4bcbace727 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -2284,21 +2284,22 @@ write_class_enum_type (const tree type) /* Non-terminal . ARGS is a TREE_VEC of template arguments. - ::= I + E */ + ::= I * E */ static void write_template_args (tree args) { int i; - int length = TREE_VEC_LENGTH (args); + int length = 0; MANGLE_TRACE_TREE ("template-args", args); write_char ('I'); - gcc_assert (length > 0); + if (args) + length = TREE_VEC_LENGTH (args); - if (TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC) + if (args && TREE_CODE (TREE_VEC_ELT (args, 0)) == TREE_VEC) { /* We have nested template args. We want the innermost template argument list. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4d6eb811876..c44b4d7e1b5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-10-23 Dodji Seketeli + + PR c++/40808 + * g++.dg/abi/mangle34.C: New test + 2009-10-23 Jason Merrill * g++.dg/cpp0x/lambda/lambda-nested2.C: New. diff --git a/gcc/testsuite/g++.dg/abi/mangle34.C b/gcc/testsuite/g++.dg/abi/mangle34.C new file mode 100644 index 00000000000..08c3bc0a19b --- /dev/null +++ b/gcc/testsuite/g++.dg/abi/mangle34.C @@ -0,0 +1,41 @@ +// Contributed by Dodji Seketeli +// Origin PR c++/40808 +// { dg-do compile } +// This tests the mangling of empty template argument list in a template +// id. +// { dg-final { scan-assembler "_ZNK5DummyclI3GenEENT_3SigIE10ResultTypeERKS2_" } } + + +struct Void {}; + +template struct FunType { + typedef R ResultType; +}; + +struct WrongNumberOfSigArgs {}; + +template struct CFunType { + template struct Sig : public +FunType {}; + template struct Sig : public FunType {}; +}; + +struct Dummy { + template typename F::template Sig<>::ResultType operator()(F +const& f) const { + return typename F::template Sig<>::ResultType(0); + } +}; + +struct Gen: public CFunType { + int operator()() const {return 0;} + Gen() {} +}; + +int myfunction() { + return Dummy()(Gen()); +} + +int main() { + myfunction(); +}