Commit 95e20768 by Nathan Sidwell Committed by Nathan Sidwell

typeck.c (cp_build_compound_expr): Require RHS to have a known type.

	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.

From-SVN: r147125
parent 66ba9b0b
2009-05-05 Nathan Sidwell <nathan@codesourcery.com>
* 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 <jakub@redhat.com> 2009-05-05 Jakub Jelinek <jakub@redhat.com>
PR c++/40013 PR c++/40013
......
...@@ -6147,7 +6147,7 @@ resolve_address_of_overloaded_function (tree target_type, ...@@ -6147,7 +6147,7 @@ resolve_address_of_overloaded_function (tree target_type,
if (flags & tf_error) if (flags & tf_error)
{ {
error ("no matches converting function %qD to type %q#T", error ("no matches converting function %qD to type %q#T",
DECL_NAME (OVL_FUNCTION (overload)), DECL_NAME (OVL_CURRENT (overload)),
target_type); target_type);
/* print_candidates expects a chain with the functions in /* print_candidates expects a chain with the functions in
...@@ -6310,13 +6310,8 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags) ...@@ -6310,13 +6310,8 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
dependent on overload resolution. */ dependent on overload resolution. */
gcc_assert (TREE_CODE (rhs) == ADDR_EXPR gcc_assert (TREE_CODE (rhs) == ADDR_EXPR
|| TREE_CODE (rhs) == COMPONENT_REF || TREE_CODE (rhs) == COMPONENT_REF
|| TREE_CODE (rhs) == COMPOUND_EXPR || really_overloaded_fn (rhs)
|| really_overloaded_fn (rhs)); || (flag_ms_extensions && TREE_CODE (rhs) == FUNCTION_DECL));
/* 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);
/* This should really only be used when attempting to distinguish /* This should really only be used when attempting to distinguish
what sort of a pointer to function we have. For now, any 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) ...@@ -6368,19 +6363,6 @@ instantiate_type (tree lhstype, tree rhs, tsubst_flags_t flags)
/*explicit_targs=*/NULL_TREE, /*explicit_targs=*/NULL_TREE,
access_path); 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: case ADDR_EXPR:
{ {
if (PTRMEM_OK_P (rhs)) if (PTRMEM_OK_P (rhs))
......
...@@ -5034,6 +5034,12 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain) ...@@ -5034,6 +5034,12 @@ cp_build_compound_expr (tree lhs, tree rhs, tsubst_flags_t complain)
return rhs; 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); return build2 (COMPOUND_EXPR, TREE_TYPE (rhs), lhs, rhs);
} }
......
2009-05-05 Nathan Sidwell <nathan@codesourcery.com>
* 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 <jakub@redhat.com> 2009-05-05 Jakub Jelinek <jakub@redhat.com>
PR c++/40013 PR c++/40013
......
// 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);
}
...@@ -7,12 +7,12 @@ template <typename T> A<T>& operator<<(A<T>&, const B<T>&); ...@@ -7,12 +7,12 @@ template <typename T> A<T>& operator<<(A<T>&, const B<T>&);
template <typename T> template <typename T>
struct A struct A
{ {
A<T>& operator<<(A<T>& (*)(A<T>&)); // { dg-message "candidate" } A<T>& operator<<(A<T>& (*)(A<T>&));
}; };
template <typename T> A<T>& foo(A<T>&); template <typename T> A<T>& foo(A<T>&);
extern A<char> c; extern A<char> c;
int main () { int main () {
c << (1, foo); // { dg-error "no match" } c << (1, foo); // { dg-error "no context" }
} }
...@@ -54,11 +54,10 @@ int main (int argc, char **argv) ...@@ -54,11 +54,10 @@ int main (int argc, char **argv)
ptr = (ovl); // ok ptr = (ovl); // ok
ptr = (&ovl); // ok ptr = (&ovl); // ok
// 13.4 indicates these are ok. ptr = (0, ovl); // ok { dg-error "no context" }
ptr = (0, ovl); // ok { dg-bogus "" "" { xfail *-*-* } } ptr = (0, &ovl); // ok { dg-error "no context" }
ptr = (0, &ovl); // ok { dg-bogus "" "" { xfail *-*-* } } ptr = (argc ? ovl : ovl); // ok { dg-error "no context" }
ptr = (argc ? ovl : ovl); // ok { dg-bogus "" "" { xfail *-*-* } } ptr = (argc ? &ovl : &ovl);// ok { dg-error "no context" }
ptr = (argc ? &ovl : &ovl);// ok { dg-bogus "" "" { xfail *-*-* } }
vptr = (ovl); // { dg-error "" } no matching candidates vptr = (ovl); // { dg-error "" } no matching candidates
vptr = (&ovl); // { dg-error "" } no matching candidates vptr = (&ovl); // { dg-error "" } no matching candidates
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment