From: Mark Mitchell Date: Mon, 2 Feb 2004 16:53:17 +0000 (+0000) Subject: re PR c++/13113 (Nice warning about &(X::m) lost) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e9525111c9a3fabe2244b57e7a6257b708b8f9f5;p=gcc.git re PR c++/13113 (Nice warning about &(X::m) lost) PR c++/13113 * init.c (build_offset_ref): Improve error recovery for invalid uses of non-static member functions. PR c++/13854 * cp-tree.h (cp_build_type_attribute_variant): New function. * class.c (build_clone): Use cp_build_type_attribute_variant. * decl.c (duplicate_decls): Likewise. * pt.c (copy_default_args_to_explicit_spec): Likewise. (tsubst_function_type): Likewise. * tree.c (build_exception_variant): Check attributes before concluding that two types are the same. (cp_build_type-attribute_variant): New method. * typeck.c (merge_types): Use cp_build_type_attribute_variant. PR c++/13907 * call.c (convert_class_to_reference): Keep better track of pedantically invalid user-defined conversions. PR c++/13113 * g++.old-deja/g++.mike/net36.C: Adjust error messages. PR c++/13854 * g++.dg/ext/attrib13.C: New test. PR c++/13907 * g++.dg/conversion/op2.C: New test. From-SVN: r77127 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index ed2a83fe020..9c3d5732edb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,24 @@ +2004-02-02 Mark Mitchell + + PR c++/13113 + * init.c (build_offset_ref): Improve error recovery for invalid + uses of non-static member functions. + + PR c++/13854 + * cp-tree.h (cp_build_type_attribute_variant): New function. + * class.c (build_clone): Use cp_build_type_attribute_variant. + * decl.c (duplicate_decls): Likewise. + * pt.c (copy_default_args_to_explicit_spec): Likewise. + (tsubst_function_type): Likewise. + * tree.c (build_exception_variant): Check attributes before + concluding that two types are the same. + (cp_build_type-attribute_variant): New method. + * typeck.c (merge_types): Use cp_build_type_attribute_variant. + + PR c++/13907 + * call.c (convert_class_to_reference): Keep better track of + pedantically invalid user-defined conversions. + 2004-02-01 Giovanni Bajo PR c++/13957 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index d391b29f88b..0aa19f12643 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -828,15 +828,19 @@ convert_class_to_reference (tree t, tree s, tree expr) LOOKUP_NORMAL); if (cand) - /* Build a standard conversion sequence indicating the - binding from the reference type returned by the - function to the desired REFERENCE_TYPE. */ - cand->second_conv - = (direct_reference_binding - (reference_type, - build1 (IDENTITY_CONV, - TREE_TYPE (TREE_TYPE (TREE_TYPE (cand->fn))), - NULL_TREE))); + { + /* Build a standard conversion sequence indicating the + binding from the reference type returned by the + function to the desired REFERENCE_TYPE. */ + cand->second_conv + = (direct_reference_binding + (reference_type, + build1 (IDENTITY_CONV, + TREE_TYPE (TREE_TYPE (TREE_TYPE (cand->fn))), + NULL_TREE))); + ICS_BAD_FLAG (cand->second_conv) + |= ICS_BAD_FLAG (TREE_VEC_ELT (cand->convs, 0)); + } } conversions = TREE_CHAIN (conversions); } diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 23ca83d56db..96e48e47e33 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -3873,8 +3873,8 @@ build_clone (tree fn, tree name) TREE_TYPE (clone) = build_exception_variant (TREE_TYPE (clone), exceptions); TREE_TYPE (clone) - = build_type_attribute_variant (TREE_TYPE (clone), - TYPE_ATTRIBUTES (TREE_TYPE (fn))); + = cp_build_type_attribute_variant (TREE_TYPE (clone), + TYPE_ATTRIBUTES (TREE_TYPE (fn))); } /* Copy the function parameters. But, DECL_ARGUMENTS on a TEMPLATE_DECL diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 0614d724be7..5e645780c11 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4154,6 +4154,7 @@ extern tree maybe_dummy_object (tree, tree *); extern int is_dummy_object (tree); extern const struct attribute_spec cxx_attribute_table[]; extern tree make_ptrmem_cst (tree, tree); +extern tree cp_build_type_attribute_variant (tree, tree); extern tree cp_build_qualified_type_real (tree, int, tsubst_flags_t); #define cp_build_qualified_type(TYPE, QUALS) \ cp_build_qualified_type_real ((TYPE), (QUALS), tf_error | tf_warning) diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index a9e0316c01d..c949c74d236 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -1266,7 +1266,7 @@ duplicate_decls (tree newdecl, tree olddecl) tree attribs = (*targetm.merge_type_attributes) (TREE_TYPE (olddecl), type); - type = build_type_attribute_variant (type, attribs); + type = cp_build_type_attribute_variant (type, attribs); TREE_TYPE (newdecl) = TREE_TYPE (olddecl) = type; } diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 6f361b082b3..2c899964589 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -1559,16 +1559,20 @@ build_offset_ref (tree type, tree name, bool address_p) a class derived from that class (_class.base.init_). */ if (DECL_NONSTATIC_MEMBER_FUNCTION_P (member)) { + /* Build a representation of a the qualified name suitable + for use as the operand to "&" -- even though the "&" is + not actually present. */ + member = build (OFFSET_REF, TREE_TYPE (member), decl, member); /* In Microsoft mode, treat a non-static member function as if it were a pointer-to-member. */ if (flag_ms_extensions) { - member = build (OFFSET_REF, TREE_TYPE (member), decl, member); PTRMEM_OK_P (member) = 1; return build_unary_op (ADDR_EXPR, member, 0); } - error ("invalid use of non-static member function `%D'", member); - return error_mark_node; + error ("invalid use of non-static member function `%D'", + TREE_OPERAND (member, 1)); + return member; } else if (TREE_CODE (member) == FIELD_DECL) { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 90455bc05db..f0350423e7c 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -1526,8 +1526,8 @@ copy_default_args_to_explicit_spec (tree decl) else new_type = build_function_type (TREE_TYPE (old_type), new_spec_types); - new_type = build_type_attribute_variant (new_type, - TYPE_ATTRIBUTES (old_type)); + new_type = cp_build_type_attribute_variant (new_type, + TYPE_ATTRIBUTES (old_type)); new_type = build_exception_variant (new_type, TYPE_RAISES_EXCEPTIONS (old_type)); TREE_TYPE (decl) = new_type; @@ -6476,7 +6476,7 @@ tsubst_function_type (tree t, TREE_CHAIN (arg_types)); } fntype = cp_build_qualified_type_real (fntype, TYPE_QUALS (t), complain); - fntype = build_type_attribute_variant (fntype, TYPE_ATTRIBUTES (t)); + fntype = cp_build_type_attribute_variant (fntype, TYPE_ATTRIBUTES (t)); return fntype; } diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 7d981285689..3413edee1d2 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -991,7 +991,8 @@ build_exception_variant (tree type, tree raises) for (; v; v = TYPE_NEXT_VARIANT (v)) if (TYPE_QUALS (v) == type_quals - && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1)) + && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), 1) + && (*targetm.comp_type_attributes) (type, v)) return v; /* Need to build a new variant. */ @@ -1962,6 +1963,23 @@ make_ptrmem_cst (tree type, tree member) return ptrmem_cst; } +/* Build a variant of TYPE that has the indicated ATTRIBUTES. May + return an existing type of an appropriate type already exists. */ + +tree +cp_build_type_attribute_variant (tree type, tree attributes) +{ + tree new_type; + + new_type = build_type_attribute_variant (type, attributes); + if (TREE_CODE (new_type) == FUNCTION_TYPE + && (TYPE_RAISES_EXCEPTIONS (new_type) + != TYPE_RAISES_EXCEPTIONS (type))) + new_type = build_exception_variant (new_type, + TYPE_RAISES_EXCEPTIONS (type)); + return new_type; +} + /* Apply FUNC to all language-specific sub-trees of TP in a pre-order traversal. Called from walk_tree(). */ diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 13380857e2c..4f635cc7b55 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -666,9 +666,9 @@ merge_types (tree t1, tree t2) /* Save space: see if the result is identical to one of the args. */ if (valtype == TREE_TYPE (t1) && ! p2) - return build_type_attribute_variant (t1, attributes); + return cp_build_type_attribute_variant (t1, attributes); if (valtype == TREE_TYPE (t2) && ! p1) - return build_type_attribute_variant (t2, attributes); + return cp_build_type_attribute_variant (t2, attributes); /* Simple way if one arg fails to specify argument types. */ if (p1 == NULL_TREE || TREE_VALUE (p1) == void_type_node) @@ -676,7 +676,7 @@ merge_types (tree t1, tree t2) rval = build_function_type (valtype, p2); if ((raises = TYPE_RAISES_EXCEPTIONS (t2))) rval = build_exception_variant (rval, raises); - return build_type_attribute_variant (rval, attributes); + return cp_build_type_attribute_variant (rval, attributes); } raises = TYPE_RAISES_EXCEPTIONS (t1); if (p2 == NULL_TREE || TREE_VALUE (p2) == void_type_node) @@ -684,7 +684,7 @@ merge_types (tree t1, tree t2) rval = build_function_type (valtype, p1); if (raises) rval = build_exception_variant (rval, raises); - return build_type_attribute_variant (rval, attributes); + return cp_build_type_attribute_variant (rval, attributes); } rval = build_function_type (valtype, commonparms (p1, p2)); @@ -722,7 +722,7 @@ merge_types (tree t1, tree t2) default:; } - return build_type_attribute_variant (t1, attributes); + return cp_build_type_attribute_variant (t1, attributes); } /* Return the common type of two types. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c33adfb6a47..e95b3019f56 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2004-02-02 Mark Mitchell + + PR c++/13113 + * g++.old-deja/g++.mike/net36.C: Adjust error messages. + + PR c++/13854 + * g++.dg/ext/attrib13.C: New test. + + PR c++/13907 + * g++.dg/conversion/op2.C: New test. + 2004-02-02 Eric Botcazou * gcc.dg/titype-1.c: Fix pasto. diff --git a/gcc/testsuite/g++.dg/conversion/op2.C b/gcc/testsuite/g++.dg/conversion/op2.C new file mode 100644 index 00000000000..b400988108d --- /dev/null +++ b/gcc/testsuite/g++.dg/conversion/op2.C @@ -0,0 +1,16 @@ +// PR c++/13907 + +struct A { + operator int & (); + operator const int & () const; +}; + + +void f(int &); +void f(const int &); + + +int main() { + const A x = A(); + f(x); +} diff --git a/gcc/testsuite/g++.dg/ext/attrib13.C b/gcc/testsuite/g++.dg/ext/attrib13.C new file mode 100644 index 00000000000..22ea97ae706 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib13.C @@ -0,0 +1,4 @@ +// PR c++/13854 + +extern char *rindex (__const char *__s, int __c) throw () __attribute__ ((__pure__)); +extern char *rindex (__const char *__s, int __c) throw () __attribute__ ((__pure__)); diff --git a/gcc/testsuite/g++.old-deja/g++.mike/net36.C b/gcc/testsuite/g++.old-deja/g++.mike/net36.C index 3ffa60e37a2..98b38eedb48 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); + void setHandler(handler); // { dg-error "candidate" } }; void f(B* b) {