From 8d82d1c83f6cfe10e2ec9a449f03b688ed68f838 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 5 May 2009 13:00:03 +0000 Subject: [PATCH] cp/ * typeck.c (cp_build_compound_expr): Require RHS to have a known type. * class.c (resolve_address_of_overloaded_function): Use OVL_CURRENT for error message. (instantiate_type): Forbid COMPOUND_EXPRs and remove code dealing with them. Do not copy the node. testsuite/ * g++.old-deja/g++.other/overload11.C: Adjust expected errors. * g++.dg/template/overload9.C: Likewise. * g++.dg/ext/ms-1.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@147125 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 9 +++++++++ gcc/cp/class.c | 24 +++-------------------- gcc/cp/typeck.c | 6 ++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/g++.dg/ext/ms-1.C | 17 ++++++++++++++++ gcc/testsuite/g++.dg/template/overload9.C | 4 ++-- gcc/testsuite/g++.old-deja/g++.other/overload11.C | 9 ++++----- 7 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/ms-1.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 808f0b01433..56e413fc780 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2009-05-05 Nathan Sidwell + + * typeck.c (cp_build_compound_expr): Require RHS to have a known + type. + * class.c (resolve_address_of_overloaded_function): Use + OVL_CURRENT for error message. + (instantiate_type): Forbid COMPOUND_EXPRs and remove code dealing + with them. Do not copy the node. + 2009-05-05 Jakub Jelinek PR c++/40013 diff --git a/gcc/cp/class.c b/gcc/cp/class.c index a20b8c4c565..6ad941510ba 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -6147,7 +6147,7 @@ resolve_address_of_overloaded_function (tree target_type, if (flags & tf_error) { error ("no matches converting function %qD to type %q#T", - DECL_NAME (OVL_FUNCTION (overload)), + DECL_NAME (OVL_CURRENT (overload)), target_type); /* print_candidates expects a chain with the functions in @@ -6310,13 +6310,8 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags) dependent on overload resolution. */ gcc_assert (TREE_CODE (rhs) == ADDR_EXPR || TREE_CODE (rhs) == COMPONENT_REF - || TREE_CODE (rhs) == COMPOUND_EXPR - || really_overloaded_fn (rhs)); - - /* We don't overwrite rhs if it is an overloaded function. - Copying it would destroy the tree link. */ - if (TREE_CODE (rhs) != OVERLOAD) - rhs = copy_node (rhs); + || really_overloaded_fn (rhs) + || (flag_ms_extensions && TREE_CODE (rhs) == FUNCTION_DECL)); /* This should really only be used when attempting to distinguish what sort of a pointer to function we have. For now, any @@ -6368,19 +6363,6 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags) /*explicit_targs=*/NULL_TREE, access_path); - case COMPOUND_EXPR: - TREE_OPERAND (rhs, 0) - = instantiate_type (lhstype, TREE_OPERAND (rhs, 0), flags); - if (TREE_OPERAND (rhs, 0) == error_mark_node) - return error_mark_node; - TREE_OPERAND (rhs, 1) - = instantiate_type (lhstype, TREE_OPERAND (rhs, 1), flags); - if (TREE_OPERAND (rhs, 1) == error_mark_node) - return error_mark_node; - - TREE_TYPE (rhs) = lhstype; - return rhs; - case ADDR_EXPR: { if (PTRMEM_OK_P (rhs)) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 5486c546b68..e34d942a06c 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5034,6 +5034,12 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain) return rhs; } + if (type_unknown_p (rhs)) + { + error ("no context to resolve type of %qE", rhs); + return error_mark_node; + } + return build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bf5888a1f70..f6ef3ef5e3a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2009-05-05 Nathan Sidwell + + * g++.old-deja/g++.other/overload11.C: Adjust expected errors. + * g++.dg/template/overload9.C: Likewise. + * g++.dg/ext/ms-1.C: New. + 2009-05-05 Jakub Jelinek PR c++/40013 diff --git a/gcc/testsuite/g++.dg/ext/ms-1.C b/gcc/testsuite/g++.dg/ext/ms-1.C new file mode 100644 index 00000000000..dcd1d0466ef --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/ms-1.C @@ -0,0 +1,17 @@ + +// MS allows more things to be pointers to member functions +// { dg-options "-fms-extensions" } + +struct X +{ + void Foo (X *); + void Bar (); +}; + +void Quux (void (X::*) ()); + +void X::Foo (X *ptr) // { dg-message "candidates" } +{ + Quux (Foo); // { dg-error "no matches" } + Quux (Bar); +} diff --git a/gcc/testsuite/g++.dg/template/overload9.C b/gcc/testsuite/g++.dg/template/overload9.C index cef8ebe9fc8..8aeab9eaa8e 100644 --- a/gcc/testsuite/g++.dg/template/overload9.C +++ b/gcc/testsuite/g++.dg/template/overload9.C @@ -7,12 +7,12 @@ template A& operator<<(A&, const B&); template struct A { - A& operator<<(A& (*)(A&)); // { dg-message "candidate" } + A& operator<<(A& (*)(A&)); }; template A& foo(A&); extern A c; int main () { - c << (1, foo); // { dg-error "no match" } + c << (1, foo); // { dg-error "no context" } } diff --git a/gcc/testsuite/g++.old-deja/g++.other/overload11.C b/gcc/testsuite/g++.old-deja/g++.other/overload11.C index 3b0cab79fd9..e8c88fd58ec 100644 --- a/gcc/testsuite/g++.old-deja/g++.other/overload11.C +++ b/gcc/testsuite/g++.old-deja/g++.other/overload11.C @@ -54,11 +54,10 @@ int main (int argc, char **argv) ptr = (ovl); // ok ptr = (&ovl); // ok - // 13.4 indicates these are ok. - ptr = (0, ovl); // ok { dg-bogus "" "" { xfail *-*-* } } - ptr = (0, &ovl); // ok { dg-bogus "" "" { xfail *-*-* } } - ptr = (argc ? ovl : ovl); // ok { dg-bogus "" "" { xfail *-*-* } } - ptr = (argc ? &ovl : &ovl);// ok { dg-bogus "" "" { xfail *-*-* } } + ptr = (0, ovl); // ok { dg-error "no context" } + ptr = (0, &ovl); // ok { dg-error "no context" } + ptr = (argc ? ovl : ovl); // ok { dg-error "no context" } + ptr = (argc ? &ovl : &ovl);// ok { dg-error "no context" } vptr = (ovl); // { dg-error "" } no matching candidates vptr = (&ovl); // { dg-error "" } no matching candidates -- 2.11.4.GIT