From c9e1b8d8e16c0c50fee1a4146f4d3ef6d3ea0b9a Mon Sep 17 00:00:00 2001 From: mmitchel Date: Wed, 31 May 2006 20:03:12 +0000 Subject: [PATCH] PR c++/27801 * call.c (perform_implicit_conversion): Do not actually perform conversions in templates. PR c++/26496 * call.c (resolve_args): Check for invalid uses of bound non-static member functions. * init.c (build_offset_ref): Return error_mark_node for errors. PR c++/27385 * decl.c (reshape_init): Robustify. (reshape_init_array_1): Likewise. PR c++/27801 * g++.dg/template/cond6.C: New test. PR c++/26496 * g++.dg/template/crash51.C: New test. * g++.old-deja/g++.mike/net36.C: Tweak error markers. PR c++/27385 * g++.dg/init/array20.C: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114278 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 15 +++++++++++++++ gcc/cp/call.c | 10 ++++++++++ gcc/cp/decl.c | 4 ++++ gcc/cp/init.c | 2 +- gcc/testsuite/ChangeLog | 12 ++++++++++++ gcc/testsuite/g++.dg/init/array20.C | 5 +++++ gcc/testsuite/g++.dg/template/cond6.C | 6 ++++++ gcc/testsuite/g++.dg/template/crash51.C | 11 +++++++++++ gcc/testsuite/g++.old-deja/g++.mike/net36.C | 2 +- 9 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/init/array20.C create mode 100644 gcc/testsuite/g++.dg/template/cond6.C create mode 100644 gcc/testsuite/g++.dg/template/crash51.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 57d0110..eaa96a5 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,18 @@ +2006-05-31 Mark Mitchell + + PR c++/27801 + * call.c (perform_implicit_conversion): Do not actually perform + conversions in templates. + + PR c++/26496 + * call.c (resolve_args): Check for invalid uses of bound + non-static member functions. + * init.c (build_offset_ref): Return error_mark_node for errors. + + PR c++/27385 + * decl.c (reshape_init): Robustify. + (reshape_init_array_1): Likewise. + 2006-05-30 Mark Mitchell PR c++/27808 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 9e69772..2167101 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -2704,6 +2704,8 @@ resolve_args (tree args) error ("invalid use of void expression"); return error_mark_node; } + else if (invalid_nonstatic_memfn_p (arg)) + return error_mark_node; } return args; } @@ -6388,6 +6390,14 @@ perform_implicit_conversion (tree type, tree expr) error ("could not convert %qE to %qT", expr, type); expr = error_mark_node; } + else if (processing_template_decl) + { + /* In a template, we are only concerned about determining the + type of non-dependent expressions, so we do not have to + perform the actual conversion. */ + if (TREE_TYPE (expr) != type) + expr = build_nop (type, expr); + } else expr = convert_like (conv, expr); diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5178bdf..bccb438 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4352,6 +4352,8 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d) } elt_init = reshape_init_r (elt_type, d, /*first_initializer_p=*/false); + if (elt_init == error_mark_node) + return error_mark_node; CONSTRUCTOR_APPEND_ELT (CONSTRUCTOR_ELTS (new_init), NULL_TREE, elt_init); } @@ -4630,6 +4632,8 @@ reshape_init (tree type, tree init) d.end = d.cur + VEC_length (constructor_elt, v); new_init = reshape_init_r (type, &d, true); + if (new_init == error_mark_node) + return error_mark_node; /* Make sure all the element of the constructor were used. Otherwise, issue an error about exceeding initializers. */ diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 533f9fb..99d5d99 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1426,7 +1426,7 @@ build_offset_ref (tree type, tree member, bool address_p) } error ("invalid use of non-static member function %qD", TREE_OPERAND (member, 1)); - return member; + return error_mark_node; } else if (TREE_CODE (member) == FIELD_DECL) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c0b7c04..7277f60 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2006-05-31 Mark Mitchell + + PR c++/27801 + * g++.dg/template/cond6.C: New test. + + PR c++/26496 + * g++.dg/template/crash51.C: New test. + * g++.old-deja/g++.mike/net36.C: Tweak error markers. + + PR c++/27385 + * g++.dg/init/array20.C: New test. + 2006-05-31 Roger Sayle * gcc.dg/builtins-54.c: New test case. diff --git a/gcc/testsuite/g++.dg/init/array20.C b/gcc/testsuite/g++.dg/init/array20.C new file mode 100644 index 0000000..06a1675 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/array20.C @@ -0,0 +1,5 @@ +// PR c++/27385 + +struct A {}; +A a[] = { 0 }; // { dg-error "initializer" } + diff --git a/gcc/testsuite/g++.dg/template/cond6.C b/gcc/testsuite/g++.dg/template/cond6.C new file mode 100644 index 0000000..e4cede3 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/cond6.C @@ -0,0 +1,6 @@ +// PR c++/27801 + +template int foo(int i) +{ + return !( (1 && i) ? 0 : 1 ); +} diff --git a/gcc/testsuite/g++.dg/template/crash51.C b/gcc/testsuite/g++.dg/template/crash51.C new file mode 100644 index 0000000..8c2553d --- /dev/null +++ b/gcc/testsuite/g++.dg/template/crash51.C @@ -0,0 +1,11 @@ +// PR c++/26496 + +template< typename _Generator> int generate_n(_Generator __gen); +struct Distribution { }; +typedef double (Distribution::* Pstd_mem)(); +int main(void) +{ + Distribution* rng; + Pstd_mem ptr; + generate_n(rng->*ptr); // { dg-error "non-static member" } +} diff --git a/gcc/testsuite/g++.old-deja/g++.mike/net36.C b/gcc/testsuite/g++.old-deja/g++.mike/net36.C index 98b38ee..3ffa60e 100644 --- a/gcc/testsuite/g++.old-deja/g++.mike/net36.C +++ b/gcc/testsuite/g++.old-deja/g++.mike/net36.C @@ -11,7 +11,7 @@ typedef void (A::*handler) (X*); class B { public: - void setHandler(handler); // { dg-error "candidate" } + void setHandler(handler); }; void f(B* b) { -- 2.7.4